The in_array() function checks if a specified value exists in an array.
in_array(find, arr, type)
find − The value to be searched
arr − The array to search
type − The mode in which the search is to be performed. If the parameter is set to TRUE, then it looks for for the search string and specific type in the array.
The in_array() function returns TRUE if the value is found in the array, or FALSE otherwise.
The following is an example −
<?php $stu = array("Tom", "Amit", "Peter", "Rahul"); if (in_array("Amit", $stu)) { echo "Match!"; } else { echo "No Match!"; } ?>
The following is the output −
Match!
Let us see another example −
<?php $pro = array("Tom", "Amit", "Peter", "Rahul", 5, 10); if (in_array(5, $pro, TRUE)) { echo "Match!"; } else { echo "No Match!"; } ?>
The following is the output −
Match!