$result = $database->loadRowList(); foreach($result as $row) { $count++; if($count > 10000) { break; } .... } 

An array of 20,000 e, you must first go through 10,000 e of the array, then again go through but the next 10,000, how do I get to the beginning of the next 10 thousand?

Update

It is necessary to find in the database duplicates of the article, and calculate if there is any info in any of the duplicate groups, if there is one, copy it to another table.

With a query, I return all duplicates to the database, then the simple scheme At the 1st stage, I expand the duplicates in one array in which there is information and another array without information, then copy the information from one array to another, then again, I check if there is a table an existing record with an ID duplicate that I want to write, if not, I delete this duplicate from the array, but at the end I write down what remains in the table. At the stage when I compare the array with the table in the database, all this does not fit into the session, I wanted to break it into stages

    1 answer 1

    There are two options to use limit in the LIMIT 0,1000 request and LIMIT 1000,2000 . This is the first option. Well, there are more options, since you roughly have one instance of the script, and there will be no difference that 10 times 1000 times that 10,000. The number of operations will not change, which means the algorithm will be identical in the first case to the second. I do not think that there is a need to iterate the array. Here we must proceed from the goal of the final result. For example, if you need to remove a duplicate, use Distinct in the request, etc.

    • Updated the question. - Vit