$search : Required , value to search inside the $input_array.
$input_array : Required , array inside which the value will be searched.
$strict :Optional : If set to TRUE then strict type comparison is performed.
Output is the corresponding key if value is found inside array , otherwise FALSE.
arra_search() returns the key of first occurance of the value, to get the keys of all the matching values we can use array_keys() function
Example 1
$input=array(1,2,3,4);
if(array_search(2,$input)){
echo "Value is available ";
}else{
echo "Value is NOT available ";
}
Output is here.
Value is available
Example 2
$input=array('One' =>1,'Two'=>2,'Three'=>3,'Four'=>'Fourth');
if(array_search('Three',$input)){
echo "Value is available ";
}else{
echo "Value is NOT available ";
}
Output is here.
Value is available
Example 3 , returning the matching key
$input=array('One' =>'First','Two'=>'Second','Three'=>'Third','Fourth');
$search_string='Third'; // Change this value
if(array_search($search_string,$input)){
echo "Value <i>$search_string</i> is available inside array<br>";
echo "Marching Key is : ".array_search($search_string,$input);
}else{
echo "Value <i>$search_string</i> is NOT available inside array <br>";
}
Output is here
Value Third is available inside array
Marching Key is : Three