可能重复:
如何对以下 PHP 多维数组进行排序?
假设我有以下数组:
Array
(
[0] => Array
(
[id] => 5
[name] => Education
[parent] => 1
[sort_order] => 3
[leaf] => 1
)
[1] => Array
(
[id] => 6
[name] => Computers
[parent] => 1
[sort_order] => 1
[leaf] => 1
)
[2] => Array
(
[id] => 7
[name] => Science
[parent] => 1
[sort_order] => 2
[children] => Array
(
[0] => Array
(
[id] => 8
[name] => Mathematics
[parent] => 7
[sort_order] => 2
[children] => Array
(
[0] => Array
(
[id] => 11
[name] => Geometry
[parent] => 8
[sort_order] => 2
[leaf] => 1
)
[1] => Array
(
[id] => 12
[name] => Algebra
[parent] => 8
[sort_order] => 1
[leaf] => 1
)
)
)
[1] => Array
(
[id] => 9
[name] => Physics
[parent] => 7
[sort_order] => 1
[leaf] => 1
)
[2] => Array
(
[id] => 10
[name] => Biology
[parent] => 7
[sort_order] => 4
[leaf] => 1
)
[3] => Array
(
[id] => 13
[name] => History
[parent] => 7
[sort_order] => 3
[leaf] => 1
)
)
)
是否有任何 PHP 内置函数可以按'sort_order'
值在每个级别上分别对该数组进行排序?我找到了几种解决方案,但它们都按字母顺序排序或使用了 ksort()。
可能需要递归,但我需要一些帮助如何开始。TIA。