I have the following arrays
$arr1 = array(
array('ctype'=>'fr', 'type'=>'fr'),
array('ctype'=>'fasdf', 'type'=>'fr'),
array('ctype'=>'fdfdf', 'type'=>'fr'),
array('ctype'=>'fhjdf', 'type'=>'fr'),
array('ctype'=>'fsf', 'type'=>'fr'),
array('ctype'=>'vndf', 'type'=>'fr'),
array('ctype'=>'fnsdf', 'type'=>'fr')
);
$arr2 = array(
array('ctype'=>'fr', 'type'=>'ln'),
array('ctype'=>'fasdf', 'type'=>'ln'),
array('ctype'=>'fayf', 'type'=>'ln'),
array('ctype'=>'fauf', 'type'=>'ln')
);
I want to merge this array into one but into chunks with difference of 2 something like
$main_arr = array(
array('ctype'=>'fr', 'type'=>'fr'),
array('ctype'=>'fasdf', 'type'=>'fr'),
array('ctype'=>'fr', 'type'=>'ln'),
array('ctype'=>'fasdf', 'type'=>'ln'),
array('ctype'=>'fdfdf', 'type'=>'fr'),
array('ctype'=>'fhjdf', 'type'=>'fr'),
array('ctype'=>'fayf', 'type'=>'ln'),
array('ctype'=>'fauf', 'type'=>'ln')
array('ctype'=>'fsf', 'type'=>'fr'),
array('ctype'=>'vndf', 'type'=>'fr'),
array('ctype'=>'fnsdf', 'type'=>'fr')
);
As you see i want to take 2 values from arr1 then 2 from arr2 and if the value not exists in like the example $arr2
then get and push the values from $arr1
. I tried it with array_chunks
and array_map
but can't get the expected.
This is what i tried:
// Divide foursome into chunks
$fr = array_chunk($arr1, 2);
$ln = array_chunk($arr2, 2);
// Can't provide the expected result
$main = array_map(NULL, $fr, $ln);