The in_array function is used to check whether an array of values exists. it is used to determine whether a specified value exists in the current array. In_array
(PHP 4, PHP 5)
In_array-check whether a value exists in the array
Description
bool in_array ( mixed $needle , array $haystack [, bool $strict ] )
Search for needle in haystack. If yes, TRUE is returned. otherwise, FALSE is returned.
If the value of the third strict parameter is TRUE, the in_array () function checks whether the needle type is the same as that in haystack.
Note: If needle is a string, the comparison is case sensitive.
Note: Before PHP version 4.2.0, needle cannot be an array.
Example #1 in_array ()
The second condition fails, because in_array () is case sensitive, so the above program is shown:
Got Irix
Example #2 in_array () strict type check Example
The above example will output:
1.13 found with strict check
Example #3 in_array () using arrays as needle
The above example will output:
'Ph 'was found
'O' was found
Note:
Suppose:
Declare an array as follows:
$ Arr = array (*);
Then there are:
In_array (0, $ arr) = true
Confusing! {Weak language}
Solution:
In_array (strval (0), $ arr, true ))
For more information about the use of php in_array functions and in_array functions, see The PHP Chinese website!