To find an element in an array in
PHP, use the
array_search method
The method will return the index of the element.
If the item is not found, the method will return
false
PHP
$my_arr1 = array();
$my_arr1[] = "Hello";
$my_arr1[] = "Home";
$my_arr1[] = "Good";
$index = array_search("Home", $my_arr1);
if ($index == false)
echo "not found";
else
echo $index;
// On the screen we will see 1
$index = array_search("Car", $my_arr1);
if ($index == false)
echo "not found";
else
echo $index;
// On the screen we will see not found