In PHP, you can use the in_array() function to directly determine whether an element is in an array. If the element exists in the array, the in_array() function returns true, otherwise it returns false. This article mainly shares with you how to use PHP to determine whether an element appears in an array. I hope it can help you.
in_array(search,array,type)
Note: Ifsearchparameter is a string, andtypeIf the parameter is set to true, the search is case-sensitive.
Since PHP 4.2, the search parameter may now also be an array
For example:
$arr=array("107","Website","Studio");
##if(in_array("107",$arr)){
echo"Matching successful";
}else{
echo"Match failed";
}
##
Description | |
---|---|
search | Required. Specifies the value to search for in the array.|
array | Required. Specifies the array to search.|
type | Optional. If this parameter is set to true, it is checked whether the type of the searched data and the value of the array are the same.
The above is the detailed content of PHP determines whether an element appears in an array. For more information, please follow other related articles on the PHP Chinese website!