There are three methods:
1. Use the in_array() function
in_array($value,$array) 注意:in_array('','',true)还有第三个参数,为true时还会判断数据类型
2. First use the array_flip() function to key the array Invert the value, and then make a judgment
if(isset($array[$value])){ }
3. First convert the array into a string, and then use the strpos function for further processing
public static function inArray($item, $array) { $str = implode(',', $array); $str = ',' . $str . ','; $item = ',' . $item . ','; return false !== strpos($item, $str) ? true : false; }
For more related tutorials, please visit php中文网.
The above is the detailed content of How to determine if a value is in an array in php. For more information, please follow other related articles on the PHP Chinese website!