I have an array, like:
$list = array('a', 'b', 'c', 'd', 'e',
'f', '1', '2', '3', '4',
'5', '6', '7', '8', '9');
And I want to split this array, and add every next two items in a new array as a group, like:
$new_list = array(
array('a', 'b'),
array('c', 'd'),
array('e', 'f'),
array('1', '2'),
array('3', '4'),
array('5', '6'),
array('7', '8'),
array('9'), // note that this one here is alone!
);
But I want to do this with foreach
or something. I only know I can divide length of my array with 2 and use round
or floor
PHP functions to get a whole number, but I can't figure out how to group items of this array in two items per array.
Please help me, my brain is overflowing...