I have an array of 18 values:
(我有18个值的数组:)
$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:
(我想将此数组拆分为12个不同的数组,因此它应如下所示:)
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
(因为我得到9个不同的数组而不是12个。它将返回)
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. (谢谢。)
ask by Daniel Harris translate from so