array_search
Search for the given value in the array, and if successful, return the first corresponding key name
array_search()
function searches for a key value in the array and returns the corresponding key name.
Search for the key value "red" in the array and return its key name:
<?php $a = array ( "a" => "red" , "b" => "green" , "c" => "blue" ) ; echo array_search ( "red" , $a ) ; ?>
Try it yourself
Search for the key value 5 in the array and return its key name (note ""):
<?php $a = array ( "a" => "5" , "b" => 5 , "c" => "5" ) ; echo array_search ( 5 , $a , true ) ; ?>
Try it yourself