Current Location: Home> Function Categories> array_search

array_search

Search for the given value in the array, and if successful, return the first corresponding key name
Name:array_search
Category:Array
Programming Language:php
One-line Description:Searches for the given value in the array and returns the key name.

Definition and usage

array_search() function searches for a key value in the array and returns the corresponding key name.

Example

Example 1

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

Example 2

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

Similar Functions
Popular Articles