In_array () Definition and usage
The In_array () function searches the array for a given value.
Grammar
In_array (Value,array,type)
Parameter description
Value required. Specify the values to search for in the array.
Array required. Specify the array to search for.
Type is optional. If this parameter is set to True, the search data is checked for the same type as the value of the array.
Description
Returns true if the value given is present in array 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 the argument is not found in the array, the function returns FALSE.
Note: If the value parameter is a string and the type argument is set to True, the search is case-sensitive.
Example 1
Copy Code code as follows:
<?php
$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 Code code as follows:
<?php
$people = Array ("Peter", "Joe", "Glenn", "Cleveland", 23);
if (In_array ("$people, TRUE)"
{
echo "Match found<br/>";
}
Else
{
echo "Match not found<br/>";
}if (In_array ("Glenn", $people, TRUE))
{
echo "Match found<br/>";
}
Else
{
echo "Match not found<br/>";
}if (In_array, $people, TRUE)
{
echo "Match found<br/>";
}
Else
{
echo "Match not found<br/>";
}
?>
Output:
Match not found
Match found
Match found