• + 2 comments

    The problem is the array_shift() function. You have to reverse the arrays with array_reverse() and on the while loop you can use array_pop() instead of array_shift(). The array_pop() function is a little bit faster because there is no need for reindexing the array.

    I found the solution by the following comment: http://php.net/manual/en/function.array-shift.php#86783