我有这个php数组:
Array ( [5] => Theme [8] => More [6] => Plugins [7] => Settings [1] => Blog [2] => Images [3] => Pages [4] => Social Media )
我需要按数组的数量对它进行排序,因此这个数组应该是:
Array ( [1] => Blog [2] => Images [3] => Pages [4] => Social Media [5] => Theme [6] => Plugins [7] => Settings [8] => More )
如何将这个数组排序到我需要的结果中?
谢谢。
编辑:我需要按多维数组的名称对数组进行排序,而不是值。
答案 0 :(得分:1)
查看ksort()
功能:
ksort($a);
var_dump($a);
输出:
array(8) {
[1]=>
string(4) "Blog"
[2]=>
string(6) "Images"
[3]=>
string(5) "Pages"
[4]=>
string(12) "Social Media"
[5]=>
string(5) "Theme"
[6]=>
string(7) "Plugins"
[7]=>
string(8) "Settings"
[8]=>
string(4) "More"
}