This article introduces the usage example of the php array function in_array and some precautions during use. For more information, see. There are many functions to operate arrays in php, and in_array is one of them. In_array functionIt is used to check whether an array of values exists. that is, it can 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. Tip 1: If the needle is a string, the comparison is case sensitive. Tip 2: 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 displayed as: Got Irix Example 2: in_array () strict type check example
Output: 1.13 found with strict check Example 3, in_array () uses arrays as needle
Output: 'Ph 'was found' o 'was found Note the following when using the php array function in_array: Suppose: declare an array: $ arr = array (*); So there is: in_array (0, $ arr) = true, which is not in line with the reality. Clever, do you understand? Solution: in_array (strval (0), $ arr, true. This article uses a few small examples to help you learn and understand the usage of the php array function in_array, and describes the details that need attention. Programmer's house. I wish you all a better learning experience. |