PHP Questions Home

Categories

Arrays
Files
Forms
Functions
Images
MySQL
Numbers
Others
Strings
Website


PHP Functions

PHP Functions


More PHP

Top Questions
Ask a Question

How do I reverse sort an array by key?


Use the 'k' for 'key', the 'r' for reverse and 'sort' for well 'sort' and what do you get it?

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
)



More arrays PHP Questions

How do I add to the end of an array and know how large the array is?
How do I remove the first element from an array?
How do I find out if a value is already in an array?
How can I reset an array in PHP?
How can I reverse sort an array keeping the correlation between the index and value?