我发现这个previous question与我想要实现的完全相似,但我想以不同的方式做到这一点。我有一系列菜单项,我已经整理成一棵带有孩子数的树。
$totalCount = 7; //defined in some previous code
Array
(
[0] => Array
(
[count] => 1
)
[1] => Array
(
[count] => 1
)
[2] => Array
(
[count] => 1
)
[3] => Array
(
[count] => 2
)
[4] => Array
(
[count] => 2
)
)
)
我希望能够将此数组排序为三个尽可能均匀且基于计数的数组。我能想到的唯一方法是通过一个巨大的递归循环。有没有一种更简单的方法可以做到这一点,我忽略了前一个问题中的for循环?
编辑1: 预期产出:
Array
(
[0] => Array
(
[0] => Array
(
[count] => 1
)
[1] => Array
(
[count] => 1
)
)
[1] => Array
(
[3] => Array
(
[count] => 2
)
)
[2] => Array
(
[2] => Array
(
[count] => 1
)
[4] => Array
(
[count] => 2
)
)
)