How to use in_array in PHP 8
in_array function checks whether a value exists in an array.
in_array in PHP 8
in_array(mixed $needle, array $haystack, bool $strict = false): bool
in_array function takes as first parameter the value that you are looking for, the
$haystack paramter is the array which should be searched for the
$needle. The last parameter
$strict indicates whether or not the types of the compared values should match too.
$needle:This paramater holds the value that you are looking for. If it is a string, the search is case sensitive.
$haystack:This paramter is the array that you want to look for in.
$strict (optional):If this value is set to true, the comparison of the values will also require matching types to yield true.
true if the
$needle could be found in the
$haystack. Otherwise it will return
$haystack = array('one', 'two', 'three'); $needle = 'two'; $result = in_array($needle, $haystack); echo strval($result);
In this example, the
in_array function returns
true because the
$needle with the value
two can be found in the