开发者

Is there any function to sort an array in reverse order?

Is there any php function built in to make it easy to take a dat开发者_运维百科abase of information and reverse the order in which it echo's while fetching it from a PHP script?

For instance a comment system, it would make it a lot easier if there was a function to reverse the order of the echo's to make the newest comment on the top.


yes...instead of echoing it out as you fetch row, you can first put the rows in an array and use rsort or arsort and then loop through and echo..or..you can do it in the mysql query (ideal) by adding ...order by columnname desc to your query


Check out http://php.net/manual/en/function.array-reverse.php

If you're returning an array from the database, this will do what you're looking for


The other option is simply to reverse the loop:

$count = count($aArray_Name);

for ( $i = $count; $i > 0; $i-- ) {
    echo $aArray_Name[$i];
}

May or may not work depending on your situation. Would most definitely be better to just modify the query as mentioned by others.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜