I would appreciate any help, given.
I have 7 separate arrays with approx. 90,000 numbers in each array (let\'s call them arrays1-arrays7). There are no duplicate num
array_merge()
is significantly slower with more elements in the array because (from php.net):
If the input arrays have the same string keys, then the later value for that key will overwrite the previous one. If, however, the arrays contain numeric keys, the later value will not overwrite the original value, but will be appended.
Values in the input array with numeric keys will be renumbered with incrementing keys starting from zero in the result array.
So this function is actually making some conditional statements. You can replace array merge with normal adding, consisting of the loop (foreach or any other) and the []
operator. You can write a function imitating array_merge, like(using reference to not copy the array..):
function imitateMerge(&$array1, &$array2) {
foreach($array2 as $i) {
$array1[] = $i;
}
}
And you will see the increase of speed really hard.