php - Return the array position of the containig array -


assuming give following array:

$array = array (     array (       'key' => 'value'     ),     array (       'key' => 'another value'     ),     array (       'key' => 'yet value'     ),     array (       'key' => 'final value'     ) ); 

what want array position of array value supplied. if searching $array value of "yet value" result should be: 2 because matching array @ position 2.

i know following:

foreach ($array $a) {     foreach ($a $k => $v) {         if ($v ===  "yet value") {             return $array[$a]; // do, want                                //  int position of $a in $array.                                //  so: $a == 2, give me 2.         }     } } 

update:

the key same

you can this, if keys same:

$v = "yet value"; $a = array_search(array("key"=>$v),$array); echo $a;//2 

http://sandbox.onlinephpfunctions.com/code/1c37819f25369725effa5acef012f9ce323f5425


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -