开发者

rsort sorting order

I have an array which contains the following numbers:

10000
900
670
600
500

I want to sort the array in that format above. Largest to smallest, thus using rsort(). However the outcome turns out to be:

900
670
600
500
10000

Looks li开发者_JAVA百科ke rsort() just looks at the first digit of the whole number to sort the array. Is there any fix to this?

Thanks,

Kevin


It may be that the numbers are actually strings. The simplest thing to do would be to use the SORT_NUMERIC flag.

rsort($array, SORT_NUMERIC);


Make sure you are calling rsort($arr, SORT_NUMERIC).


Try including the SORT_NUMERIC flag.

rsort($myArray, SORT_NUMERIC);

http://www.php.net/manual/en/function.sort.php

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜