How do I reverse sort an array by key?
You guessed it... krsort - getting good at this PHP lark now!
Here's the obligatory quick example:
<?php
$myworld = array("a"=>"PHP","b"=>"learning","c"=>"I'm");
krsort($myworld);
print_r($myworld);
?>
Which confirms your suspicions:
Array
(
[c] => I'm
[b] => learning
[a] => PHP
)
Comment on this Question and Answer >>>
ASK A QUESTION
More arrays PHP Questions
How do I find out if a value is already in an array?How do I find if a value is already in an array or not?
How do you remove duplicate values from an array?
Hi. i have a music samples website. in one table, id like a different sample to appear every time the page is refreshed. how do i acheve this? how can i alterate and retrieve these bloody mp3's? surely i can use a PHP script? thankyou
I have an array of a hundred or so lines, each line has data with "|" separated values. I need to scan through this array, and select the line whose first 5 characters matches a text string. Any ideas or questions?
