Page 1 of 1

Order values from highest to lowest

Posted: Thu May 14, 2009 5:35 am
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

Re: Order values from highest to lowest

Posted: Thu May 14, 2009 6:04 am
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

Re: Order values from highest to lowest

Posted: Thu May 14, 2009 6:09 am
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.

Re: Order values from highest to lowest

Posted: Thu May 14, 2009 9:45 am
by pickle

Code: Select all

$sorted_args = rsort(func_get_args());