Order values from highest to lowest

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lovelf
Forum Contributor
Posts: 153
Joined: Wed Nov 05, 2008 12:06 am

Order values from highest to lowest

Post by lovelf »

Code: Select all

$vala=1; $valb=8; $valc=4; $vald=15;
 
function orderthem($first,$second,$third,$fourth){
what could I do here? // If I'm on the right track...
return $ordered_list;
}
 
$ordered_list=orderthem($vala,$valb,$valc,$vald);
 
How could I order them from highest to lowest?
To display 15,8,4,1
philln
Forum Newbie
Posts: 12
Joined: Thu Apr 23, 2009 9:22 am

Re: Order values from highest to lowest

Post by philln »

You can sort arrays using the asort() function.
The arsort() function will sort them in reverse order.

Have a look at the php manual pages and see if it helps
http://uk2.php.net/asort
http://uk2.php.net/arsort
divito
Forum Commoner
Posts: 89
Joined: Sun Feb 22, 2009 7:29 am

Re: Order values from highest to lowest

Post by divito »

Where do the values come from? Depending on how they are coming in and what you need it sorted for will make a difference on a way to sort them.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Order values from highest to lowest

Post by pickle »

Code: Select all

$sorted_args = rsort(func_get_args());
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply