Problem while ordering an array in PHP
Well I have a PHP array like this:
Array
(
[0] => post9.post
[3] => post8.p开发者_运维知识库ost
[4] => post4.post
[5] => post7.post
[6] => post5.post
[7] => post10.post
[8] => post3.post
[9] => post6.post
[10] => post1.post
[11] => post2.post
)
But after trying all the PHP array functions I don't manage to sort it in this way:
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
)
I already made a question like this, which seemed to work but now it doesn't works :(
EDIT: After using rsort
it looks like this:
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
)
Almost good, except that post10.post should be [0]
and is [8]
You need to use natsort and then reverse the order.
natsort($array);
$array = array_reverse($array);
精彩评论