Skip to content

Instantly share code, notes, and snippets.

@arjenblokzijl
Last active May 16, 2018 07:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arjenblokzijl/909c08202899c641650e to your computer and use it in GitHub Desktop.
Save arjenblokzijl/909c08202899c641650e to your computer and use it in GitHub Desktop.
Split WireArray/PageArray into chunks
<?php
// Thanks to netcarver > https://processwire.com/talk/topic/7803-implement-array-chunk/?p=75573
$items = $pages->find('#whatever'); // Find your stuff
$parts = 3; // How many items should there be in 1 chunk?
$chunked = array_chunk($items->getArray(), $parts);
foreach ($chunked as $chunk) {
foreach ($chunk as $item) {
// Do stuff like echo $item->title;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment