ThePsion5 Posted August 8, 2006 Share Posted August 8, 2006 Hi again,I have a function that outputs a rather large associative array in a order based on the values in the array. It starts being completely unordered, but i need to arrange it in an order similar to this: word1 => 40word2 => 37other thing => 20something => 17else => 15as in, ordered by the array values instead of the associative keys. I know that I can do this using the aSort() function, but this sorts them in reverse order, which means I have to use the array_reverse() function to flip it around the way I want it. I'm trying to find a way to eliminate that costly call to array_reverse(), but in order to do that I need to use a for loop that runs in reverse, like this:for($i = $count; $i > 0; $i--){$Output .= array[$i] . "\n";} But i need to access the associative array keys in this for loop. Is there any way to do it? Link to comment Share on other sites More sharing options...
skym Posted August 8, 2006 Share Posted August 8, 2006 How about arsort() ?http://ro2.php.net/manual/en/function.arsort.phpTo access the keys of an array use can use foreach(). Link to comment Share on other sites More sharing options...
ThePsion5 Posted August 8, 2006 Author Share Posted August 8, 2006 arsort() is actually exactly what I need, thanks. :)Dunno how I missed that in the documentation though... Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now