I need to compare a value to a set of array. However, I need to compare multiple values in foreach. If using in_array, it can be slow, real slow. Is there any faster alternative? My current code is
foreach($a as $b){
in_array($b, $array);
}
Thank you.
You could use
array_diffto compute the difference between the$aarray against$array. This would give you all the values not in$arrayor$a.Example from Manual:
Or you can use
array_intersectto find those that are in those arrays.array_intersectExample from PHP Manual:Pick the one you need.