Merge two collections A and B, Adding one of every item B after every nth item A

Hi,

I’m trying to merge two collections into a new one by adding one item of $B to every nth item of $A:

  $A =        $programItems->
                  filter(function($child) {	
                  $child->date("Y-m-d", 'start_date') < date("Y-m-d") && 
                  $child->date(null, 'start_date') > strtotime('-6 month') &&
                  !($child->hasChildren()) ; 
                });

  $B =        $pages->
              find('programs')->
              children()->
              find('events','projects')->
              index()->
              visible()->
                 return
                 !($child->hasChildren());  })->
              shuffle()->
              limit(10);       

I’ve trawled through the forum and have seen:

$pages-&gt;add($collection);

But can’t figure out an elegant way to do the above without resulting to some kind of loop.

thanks!

Scratched my own itch and created a pages method:

/**************************************************	
	
Interleave
Returns a new collections with item A inserted for every nth item B

**************************************************/

pages::$methods['interleave'] = function($pages, $items, $chunkNum=2) {

	$newItems = new Pages();
	$pagesChunks = $pages->chunk($chunkNum);
	$i=0; 

	foreach ($pagesChunks as $chunkItems) {

		$newItems->add($items->nth($i));
		$newItems->add($chunkItems);
		$i++;
		}
	
		return $newItems;

	  };

Usage:

$C = $A->interleave($B,4);