Hi, just a correction, I meant array_diff when i wrote array_intersect. array_diff is more handy since just count($res)==0 is enough, $res is the returned array of array_diff().
Andrey
Andrey Hristov wrote:
So, I did now some testing. Looks like in_array_all() is 6x faster than array_intersect()
the haystack is 10 elements, and needles are 3.
When 1000 elements in haystack, the fastest time (when the needles are in the beggining
in_array_all is 300x faster. When the whole haystack should be traversed it's about 250x
faster than array_intersect. When one of the needles is not in the haystack : 300x .
Script :
<?php $i = 0; while ($i++ < 1000) { $a[] = $i; } $start = microtime(1); $res = in_array_all(100, 2, 3, $a, true); $end = microtime(1); printf("Time : %3.5f\n",$end - $start); $needles = array(100, 2, 3); $start = microtime(1); $diff = array_diff($needles, $a); $end = microtime(1); var_dump($diff); printf("Time : %3.5f\n",$end - $start);
?> [EMAIL PROTECTED]:~/dev/5_0> ./php s.php bool(true) Time : 0.00010 array(0) { } Time : 0.03888
Andrey
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php