I have the below arrays that I have combined into one. The second array, $ads, is inserted at random into the first array, $EM_Events, but the items inserted always stay together when inserted. I would like for them to be inserted at random throughout the first array, not stay together, and not alter the order of the first array. What am I missing?
$EM_Events = EM_Events::get( array(
'scope'=>'future',
'limit'=>6,
'category'=>'6'
));
$ads = EM_Events::get( array(
'scope'=>'future',
'limit'=>2,
'category'=>'56'
));
$offset = array_rand($EM_Events);
array_splice($EM_Events, $offset, 0, $ads);
array_splicewill only ever perform a single insertion, at some offset in the array, so as you say your second array will stay together.You will need to loop through all the elements of your second array and insert each in turn. Something like (untested):
or perhaps