In_array () Definition and usage
The In_array () function finds whether the specified value exists in the array.
Grammar
In_array (value,array,type) parameter description
Value is required. Specifies the value to search for in the array.
Array required. Specifies the array to search for.
Type is optional. If set to true, checks whether the searched data is the same as the type of the array's value.
Description
Returns true if the given value exists in an array of arrays. If the third argument is set to True, the function returns true only if the element exists in the array and the data type is the same as the given value.
If no arguments are found in the array, the function returns FALSE.
Note: If the value parameter is a string and the type parameter is set to True, the search is case-sensitive.
Example 1
Copy the Code code as follows:
$people = Array ("Peter", "Joe", "Glenn", "Cleveland");
if (In_array ("Glenn", $people))
{
echo "Match found";
}
Else
{
echo "Match not Found";
}
?>
Output:
Match found Example 2
Copy the Code code as follows:
$people = Array ("Peter", "Joe", "Glenn", "Cleveland", 23);
if (In_array ("@", $people, TRUE))
{
echo "Match found
";
}
Else
{
echo "Match not found
";
}if (In_array ("Glenn", $people, TRUE))
{
echo "Match found
";
}
Else
{
echo "Match not found
";
}if (In_array ($people, TRUE))
{
echo "Match found
";
}
Else
{
echo "Match not found
";
}
?>
Output:
Match not found
Match found
Match found
The above describes the PHP array function sequence of In_array-find the array in the existence of the specified value, including the content of the contents, I hope that the PHP tutorial interested in a friend helpful.