By the way, in your solution, instead of
for($i = 0; $i < 100000; $i++)
try
for($i = 0; $i < count($array2); $i++)
this way you only copy the entries that really exist in $array2
But don't forget to clear array1 before, otherwise if your $array1 was longer than $array2, $array1 will be $array2 plus whatever was left from the old $array1