pme*_*ino 1 php arrays sorting
好吧,我有一个像这样的PHP数组:
Array
(
[0] => post9.post
[3] => post8.post
[4] => post4.post
[5] => post7.post
[6] => post5.post
[7] => post10.post
[8] => post3.post
[9] => post6.post
[10] => post1.post
[11] => post2.post
)
Run Code Online (Sandbox Code Playgroud)
但在尝试所有PHP数组函数后,我无法以这种方式对其进行排序:
Array
(
[0] => post10.post
[1] => post9.post
[2] => post8.post
[3] => post7.post
[4] => post6.post
[5] => post5.post
[6] => post4.post
[7] => post3.post
[8] => post2.post
[9] => post1.post
)
Run Code Online (Sandbox Code Playgroud)
我已经提出了这样的问题,这似乎有效,但现在它不起作用:(
编辑:使用后rsort它看起来像这样:
Array
(
[0] => post9.post
[1] => post8.post
[2] => post7.post
[3] => post6.post
[4] => post5.post
[5] => post4.post
[6] => post3.post
[7] => post2.post
[8] => post10.post
[9] => post1.post
)
Run Code Online (Sandbox Code Playgroud)
几乎不错,除了post10.post应该是[0]和[8]
您需要使用natsort然后反转订单.
natsort($array);
$array = array_reverse($array);
Run Code Online (Sandbox Code Playgroud)