I have an array with say 400 (but could be anything) names i want to send to an API, but the API only receives a max of 200 requests per time, how do i chunk my array so that for every 200th item, i perform an action?
Here's what i have so far, rather than making my API request, i'm just trying to output the array's to the page.
<?php
for ($i = 0; $i <= $smsListLimit; $i++)
{
if ($i <= 199)
{
array_push($newarray, $smsList[$i]);
if ($i == 199)
{
echo “ < pre > “;
var_dump($newarray);
echo “ < / pre > “;
echo “!!!!!!!BREAK!!!!!!!“;
}
}
elseif ($i > 199 && $i <= 399)
{
unset($newarray);
array_push($newarray, $smsList[$i]);
if ($i == $smsListLimit)
{
echo “ < pre > “;
var_dump($newarray);
echo “ < / pre > “;
echo “!!!!!!!BREAK!!!!!!!“;
}
}
}
die();
?>
This returns the first 200 into an array, but not the remainder - but regardless, if the incoming array was 5000, i don't want to have to write a massive if statement for every 200.
Anyone offer any suggestions?