开发者

How do I sort while still keeping the same array indices?

The index is automatic, the indexes are 0, 1, 2, etc. nothing special.

But the key to the database is auto-incremented. meaning the index directly correlates to the key of the database. So after the sort, I can do a query and retrieve the info on that row with that key.

But I think that once you sor开发者_如何学运维t(), it changes the index, therefore I would lose that correlation between the index and the key of the database therefore making the array quite useless...so my question is how do I keep that correlation while still sorting so that the highest value goes to the top?

And then after that's successful, how do I sort through an array like that?

Thanks so much for your help and patience,

Binny


I think what you want is asort() or arsort(). According to the documentation for asort(),

This function sorts an array such that array indices maintain their correlation with the array elements they are associated with. This is used mainly when sorting associative arrays where the actual element order is significant.

arsort() sorts in the reverse direction.


Use asort: http://www.php.net/manual/en/function.asort.php

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜