I have an array of 1000 emails.
And I want to split the array into n arrays having 45 emails in each array.
I want to separately access the splitted arrays.
How can we implement using php. I have also tried array_splice()
function in php, but it returns splitted arrays, but I unable to access the splitted array.
You could use array_chunk()
in this case to get batches of those emails:
$emails = array('email1', 'email2', ..... 'email1000');
// 45 each batch
$batch_emails = array_chunk($emails, 45);
foreach($batch_emails as $batch) {
print_r($batch);
}
// or explicitly get batch/group 5
print_r($batch_emails[4]);
try this -
$f = array_chunk($yourArray, 45);
var_dump($f);
Chunks an array into arrays with size elements. The last chunk may contain less than size elements.