I have an array of 18 values:
$array = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r');
I want to split this array into 12 different arrays so it should look like this:
array(
0 => array('a', 'b'),
1 => array('c', 'd'),
2 => array('e', 'f'),
3 => array('g', 'h'),
4 => array('i', 'j'),
5 => array('k', 'l'),
6 => array('m'),
7 => array('n'),
8 => array('o'),
9 => array('p'),
10 => array('q'),
11 => array('r')
)
My function doesn't seem to work
function array_split($array, $parts){
return array_chunk($array, ceil(count($array) / $parts));
}
$result = array_split($array, 12);
because I get 9 different arrays instead of 12. It would return
array(
0 => array('a', 'b'),
1 => array('c', 'd'),
2 => array('e', 'f'),
3 => array('g', 'h'),
4 => array('i', 'j'),
5 => array('k', 'l'),
6 => array('m', 'n'),
7 => array('o', 'p'),
8 => array('q', 'r')
)
How would I go about doing this? Thanks.
Management requested that I get a list of countries, but the first two countries in our DB should be considered the same and need to be grouped together
. – Sparkle