PHP Questions Home
Categories
Arrays
Files
Forms
Creating PDFs
PHP Errors
Functions
Images
MySQL
Numbers
Others
Strings
Website

PHP Forums
Forums Index
MySQL Forum
PHP Forum
Flash/Actionscript
Javascript
Web design

More PHP
PHP Functions
Top Questions
Ask a Question
PHP Interview Questions
PHP Jobs
Ecommerce
IT Questions
Business Websites

Sponsors

sponsor ad
My Salary
PHP Developer Salary
Advertise Here

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
)



ASK A QUESTION

More arrays PHP Questions

How can I loop through the members of an array?

How do we sort an array of names taken from a text file, displaying only unique names?

How can I easily view all members of an array?

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?

how can you reset an array in PHP



Custom Search