in_array
Checks if a value exists in an array.
Parameters
main.php
Return Values
bool
Returns whether the needle is found in the haystack
On success:true if needle is found in the array
On failure:false if needle is not found
Notes
- Function is case-sensitive when searching for strings
- Set strict parameter to true for type-safe comparisons
- Prior to PHP 8.0, string needles matched array values of 0 in non-strict mode
- Use strict mode to avoid unexpected type conversion behavior
Changelog
- 8.0.0: Passing a needle that is not supported by the haystack will now throw a TypeError
Related Functions
strpos
StringFinds the position of the first occurrence of a substring within a string.
searchpositionfind
filter_var
ValidationFilters a variable with a specified filter, used for validating and sanitizing data.
validatesanitizesecurity
array_search
ArraySearches an array for a specific value and returns the corresponding key if found, or false if not found.
searchfindkey