in_arrayChecks if a value exists in an array
&reftitle.description;
boolin_arraymixedneedlearrayhaystackboolstrict&false;
Searches for needle in haystack using loose comparison
unless strict is set.
&reftitle.parameters;
needle
The searched value.
If needle is a string, the comparison is done
in a case-sensitive manner.
haystack
The array.
strict
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.
Prior to PHP 8.0.0, a stringneedle will match an array
value of 0 in non-strict mode, and vice versa. That may lead to undesireable
results. Similar edge cases exist for other types, as well. If not absolutely certain of the
types of values involved, always use the strict flag to avoid unexpected behavior.
&reftitle.returnvalues;
Returns &true; if needle is found in the array,
&false; otherwise.
&reftitle.examples;
in_array example
]]>
The second condition fails because in_array
is case-sensitive, so the program above will display:
in_array with strict example
]]>
&example.outputs;
in_array with an array as needle
]]>
&example.outputs;
&reftitle.seealso;
array_searchissetarray_key_exists