Search code examples
phparrayssortinginteger

Sorting an array of numeric strings in a descending direction


I am trying to sort an array that contains numbers that range in substantial values. The result I want to get is a descending order of those numbers from the array I am retrieving from a MySQL Server. So far I have created this to test out the "sort" function:

<?php

$numbers = array("100", "50", "70", "1000");
sort($numbers);
echo var_dump($numbers);

?>

And the result I get is this:

array(4) { [0]=>  string(2) "50" [1]=>  string(2) "70" [2]=>  string(3) "100" [3]=>  string(4) "1000" } 

I can see that the numbers are listing from smallest to largest, but I want it to list from the biggest integer to the smallest integer.


Solution

  • rsort() reverse sorts the array :)