1 2 3 4 |
$dog=array("Volvo"=>"XC90","BMW"=>"X5","Toyota"=>"Highlander"); echo $i = array_search('Volvo', array_keys($dog)); |
If you have keys already and your array looks more like this
1 2 3 |
$array = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red'); |
Then use this
1 2 3 |
$key = array_search('green', $array); // $key = 2; |