Jump to content

Sorting a Numeric Array


xProteuSx

Recommended Posts

I have an array that looks like this:

 

Array ([0] => 1  [3] =>  [4] => 285 [6] => 190)

 

and I would like to sort it from highest value to lowest.

 

As is, when I print_r() this array, I get:

 

1

104

285

190

 

I would like to get:

 

1

104

190

285

 

I have tried the following:  sort(), asort(), ksort(), and krsort().

 

What else can I try?

 

My code looks like this:

 

$countries_array = array_unique($countries_array);
print_r($countries_array);
 
which returns:
 

1

104

285

190

 
 
However, when I do this:
 
$countries_array = array_unique($countries_array);
$countries_array = sort($countries_array);
print_r($countries_array);
 
It simply returns:  1
 
Thanks in advance.
Link to comment
https://forums.phpfreaks.com/topic/287866-sorting-a-numeric-array/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.