What, and how much, is faster - manually iterating over an array with foreach
and checking for needle
occurrence with in_array()
, or using array_intersect()
?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
Benchmark
Test Script
Output
Fiddle: http://ideone.com/OZ2Idf
Conclusion
array_intersect
is much faster thanforeach
+in_array
.Why is
array_intersect
faster?