This article introduces the usage of the in_array() function of the PHP array function. Friends in need can refer to it.
In the php array function, the in_array() function searches for a specific value in an array and returns true if the value is found, otherwise it returns false. The form is as follows: boolean in_array(mixed needle,array haystack[,boolean strict]); Example, find whether the variable apple is already in the array, if so, output a piece of information: <?php //in_array用法举例 //by bbs.it-home.org $fruit = "apple"; $fruits = array("apple","banana","orange","pear"); if( in_array($fruit,$fruits) ) echo "$fruit 已经在数组中"; ?> Copy after login Instructions: The third argument is optional and forces in_array() to consider types when searching. |