How to Find Value in PHP Array

PHP Find Value in Array

To find value in PHP array, we need to use the in_search() in-built function. Some people use the search_array function if we use it to return index value only, so we can use the in_array function instead of the search_array function. The in_array() function looks through an array for a specified value and returns true if found.

Ex:

<?php
// create an array
$fruits = array("orange", "apple", "banana", "Mango");

// searching array values
if (in_array("orange", $fruits))
{
echo "Match found";
}
else
{
echo "Match not found";
}
?>

Output:

Match found

See the above output, we have “match found” which means. The value “orange” is in the array “fruits”.

Leave a Reply