This function looks through an array for a given value. If found, it gives you back the key of the first occurrence. If that value is not in the array, it returns false.

While the array may be multidimensional, this function will only check values one level deep. Set the third parameter to true in order to be strict when checking the values and compare type as well.

$arr = array('a' => 'apple',
             'b' => 'banana',
             'c' => 'carrot',
             'd' => false,
             'e' => 1,
             'f' => array('a', 'b'),
             'g' => '17');
 
$key = array_search('banana', $arr); // b
$key = array_search(false, $arr);    // d
 
// Being strict with type
$key = array_search('', $arr);       // d
$key = array_search('', $arr, true); // false
$key = array_search(17, $arr);       // g
$key = array_search(17, $arr, true); // false
 
// Only looks one level deep
$key = array_search('a', $arr);             // false
$key = array_search(array('a', 'b'), $arr); // f