I have an array that can hold up to several thousands of items.(usually around 5000 items).
I need to split this array into hundreds and process them and then continue with the rest of items.
So far i handle the whole array which is slow.
My code is
foreach($result as $p){
$sqlQuery = mysql_query("INSERT INTO message_details(contact, message_id)VALUES('$p', $message_last_id)");
$last_id = mysql_insert_id();
$xmlString .= "<gsm messageId=\"$last_id\">".$p."</gsm>";
$cnt++;
}
How can i process the items in the array in hundreds? Eg. 100, then 200, then 300 etc
Best Regards,
Nicos
If you have to do it in the code the you can use the php function array_chunk to chunk your array into arrays of 100 elements each. Here’s the docs on array_chunk: link. But as pointed out this is unlikely to be the bottle neck.