in_array() function checks whether the specified value exists in the array.
in_array(find, arr, type)
find - The value to search for
arr - The array to search
type - The pattern to perform the search on. If this parameter is set to TRUE, it will look for the search string and specific type in the array.
in_array()The function returns TRUE if the value is found in the array, otherwise it returns FALSE.
The following is an example-
Real-time demonstration
<?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’s see another example-
Live Demonstration
<?php $pro = array("Tom", "Amit", "Peter", "Rahul", 5, 10); if (in_array(5, $pro, TRUE)) { echo "Match!"; } else { echo "No Match!"; } ?>
Here is the output-
Match!
The above is the detailed content of Use of in_array() function in PHP. For more information, please follow other related articles on the PHP Chinese website!