bool = array_search ($search, $input_array,$strict);
$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.
$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
$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
$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
More functions to search an array.
Function | Details |
---|---|
in_array() | Search for value inside Array. Returns TRUE or FALSE |
array_key_exists() | Returns TEUE if key is found inside, FALSE otherwise |
array_keys() | Array of keys for matching values, FALSE otherwise |
$student=array('Ron'=>15,'Geek'=>25,'Alex'=>13,'Ravi'=>14);
echo "highest mark : ". max($student); // output 25
echo "<br>";
echo "Student got highest mark:".array_search(max($student),$student);
echo "<br>";
echo "Lowest mark : ". min($student); // output 13
echo "<br>";
echo "Student got Lowest mark:".array_search(min($student),$student);
Output is here.
highest mark : 25
Student got highest mark : Geek
Lowest mark : 13
Student got Lowest mark : Alex
Difference between arrays considering values
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.