PHP array_search() Function

The array_search() function is used to search the array against the given value. The function returns the first corresponding key if successful.

Returns the key of a value if it is found in the array, and FALSE otherwise. If the value is found in the array more than once, the first matching key is returned.

Parameter Description
value Required. Specifies the value to search for
array Required. Specifies the array to search in
strict Optional. If this parameter is set to TRUE, then this function will search for identical elements in the array. Possible values:

  • true
  • false – Default

When set to true, the number 5 is not the same as the string 5 (See example 2)




$array = array("a"=>"Cooper","b"=>5,"c"=>"6");
echo array_search("Cooper",$array,true);



Leave a Reply

Your email address will not be published. Required fields are marked *