PHP array_search()


array_search() searches an associative array for a specified value and returns its key if found, otherwise false.

<?PHP
	$arr=array("apple"=>"carbon","rice"=>"carbon","nuts"=>"fat","meat"=>"protein");
    $key=array_search("fat",$arr);
	echo $key; //nuts 
?>

If there are more than one key with the same value, the first occurrence will be returned.
<?PHP
	$arr=array("apple"=>"carbon","rice"=>"carbon","nuts"=>"fat","meat"=>"protein");
    $key=array_search("carbon",$arr);
	echo $key; //apple
?>