I'm still not sure I follow what you're doing here.
The termination of the inner loop can be caused by either no hasNext tokens, j exceeding the size of pages, or i exceeding the size of B. Given what is occurring within the for loop, that would peg my suspicion on the i exceeding that of B.
What's the purpose of this outer for loop? I'm still not seeing a need for multiple arrays either, if you plan on merging them in the end, keeping separate arrays will just complicate the sorting algorithms.
header('HTTP/1.1 420 Enhance Your Calm');