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
Post a Comment