But if the array is larger, the performance will drop and it will run for a long time, so if you are optimizing for a large array, here are two methods (implemented by custom functions):
1. Array key and value flip through isset to determine whether the key exists in the array code is as follows:/** * In_array is too slow the When array is large   ; */public static function InArray ($item, $array) { $flipArray = Array_flip ($array); Return is Set ($flipArray [$item]); You may also ask why you do not use array_key_exists to make judgments. isset? Here's a comparison between array_key_exists () and Isset (): Isset () does not return true for values that are null in the array, array_key_exists (). Code as follows: <?php $search _array = array (' => null, ' second ' => 4); //returns false Isset ($search _array[' a ']); //Returns True Array_key_exists (' i ', $search _array);?> 2. Use implode connection, directly use Strpos to judge use implode function + comma connected, directly with strpos judgment. PHP inside the string to take position very fast, especially in the case of large amount of data. However, it is necessary to pay attention to the end of the ",", so more rigorous. such as:, User1,user2,user3, find the time, check, User1,. There are also strpos to use!== false because the first one will return 0. Examples are as follows: The code is as follows:/** * In_array is too slow the When the array is large */public static function InArray ($item , $array) { $STR = implode (', ', $array); $STR = ',' . $str. ','; $item = ', '. $item. ','; return false!== Strpos ($item, $str)? True:false; }