我每周有以下数天,每天有时数(整个数组代表非全日雇员的时间表):
Array
(
[7] => Array
(
[0] => 15
[1] => 14
[2] => 13
[3] => 11
[4] => 12
[5] => 10
)
[1] => Array
(
[0] => 10
[1] => 13
[2] => 12
)
[6] => Array
(
[0] => 14
)
[3] => Array
(
[0] => 4
[1] => 5
[2] => 6
)
)
我只需要:
- sort asc each sub-array (2nd dimension) - no need to maintain the numeric keys, values are integers
- sort asc the 1st dimension and maintain the numeric, integer keys
:
Array
(
[1] => Array
(
[0] => 10
[1] => 12
[2] => 13
)
[3] => Array
(
[0] => 4
[1] => 5
[2] => 6
)
[6] => Array
(
[0] => 14
)
[7] => Array
(
[0] => 10
[1] => 11
[2] => 12
[3] => 13
[4] => 14
[5] => 15
)
)
附加信息 :
- only the keys of the 1st dimension and the values of the 2nd dimension (and of course their association) are meaningful to my use-case
- the 1st dimension can have at most 7 values, ranging from 1-7 (days of the week), and will have at least 1 value (1 day)
- the 2nd dimension can have at most 24 values, ranging from 0-23 (hours of each day), and will have at least 1 value (1 hour per day)
整个 < code>ksort 和 sort
每个二维数组的 < code> 都可以做到这一点:
ksort($sched);
foreach ($sched as &$array) sort($array);
unset($array);
但我希望我可以用本地的 php 阵列函数实现这一点。
我的搜索让我尝试了 arry_ multisort( array_ values ($array) 、 数组_ keys ($array) 、 $array) code >, 但我无法让它生效 。