按他的值的 1 对多维数组进行排序
Sorting a Multidimensional Array by 1 of his value
首先,我检查并尝试了这些链接:
Sort Multi-dimensional Array by Value
Sort Multi-dimensional Array by Value
Sort php multidimensional array by sub-value
所以这是我的问题。我需要根据键的值将数组排序为多维数组。
如果我这样做,这就是结构:print($myarray)
Array (
[afctname1] => Array (
[active] => 1
[icons] => Array (
[0] => Array (
[permalink] => afctname1
[ordering] => 2
)
)
)
Array (
[afctname2] => Array (
[active] => 1
[icons] => Array (
[0] => Array (
[permalink] => afctname2
[ordering] => 0
)
)
)
Array (
[afctname3] => Array (
[active] => 1
[icons] => Array (
[0] => Array (
[permalink] => afctname3
[ordering] => 1
)
)
)
所以我想要的只是按键“ordering”中的值对数组进行排序。
有人可以给我提示或帮助我进行演示吗?
谢谢
function cmp($a, $b)
{
return $a['icons'][0]['ordering'] - $b['icons'][0]['ordering'];
}
usort($theArray, "cmp");
首先,我检查并尝试了这些链接:
Sort Multi-dimensional Array by Value
Sort Multi-dimensional Array by Value
Sort php multidimensional array by sub-value
所以这是我的问题。我需要根据键的值将数组排序为多维数组。
如果我这样做,这就是结构:print($myarray)
Array (
[afctname1] => Array (
[active] => 1
[icons] => Array (
[0] => Array (
[permalink] => afctname1
[ordering] => 2
)
)
)
Array (
[afctname2] => Array (
[active] => 1
[icons] => Array (
[0] => Array (
[permalink] => afctname2
[ordering] => 0
)
)
)
Array (
[afctname3] => Array (
[active] => 1
[icons] => Array (
[0] => Array (
[permalink] => afctname3
[ordering] => 1
)
)
)
所以我想要的只是按键“ordering”中的值对数组进行排序。
有人可以给我提示或帮助我进行演示吗? 谢谢
function cmp($a, $b)
{
return $a['icons'][0]['ordering'] - $b['icons'][0]['ordering'];
}
usort($theArray, "cmp");