in_arrayChecks if a value exists in an arrayDescriptionboolin_arraymixedneedlearrayhaystackboolstrict
Searches haystack for
needle and returns &true;
if it is found in the array, &false; otherwise.
If the third parameter strict is set to
&true; then the in_array function
will also check the types of
the needle in the haystack.
If needle is a string, the comparison is done in
a case-sensitive manner.
In PHP versions before 4.2.0 needle was not
allowed to be an array.
in_array example
]]>
The second condition fails because in_array
is case-sensitive, so the program above will display:
in_array with strict example
]]>
This will display:
in_array with an array as needle
]]>
Outputs:
See also array_search,
array_key_exists, and
isset.