The array_diff() function of PHP 5.2.6 and above takes an extremely long time when processing large arrays. This bug has been officially confirmed; before this problem is fixed or when we cannot control the PHP version, you can Use the method provided in this article
cisa Submit it to the PHP official BUG page
The code is as follows:
$key) { if (isset($data1[$hash])) unset($data1[$hash]); } return array_flip($data1); } ?>
According to the idea of ChinaUnix Forum moderator hightman The rewritten method
The code is as follows:
$value) { // 如果第二个数组中存在第一个数组的值 if (isset($secondArray[$value])) { // 移除第一个数组中对应的元素 unset($firstArray[$key]); } } return $firstArray; } ?>
This method only exchanges the key and value of the second array, so it is more efficient.
Note: PHP's built-in array_diff() function can handle multiple arrays, but the method provided in this article only handles the comparison of two arrays.
The above is the detailed content of Detailed explanation of the timeout BUG problem of PHP's array_diff() function when processing large arrays. For more information, please follow other related articles on the PHP Chinese website!