How to sort an array of numeric strings in descending order with PHP

2 Answers

0 votes
$array = array("7", "0", "55", "8", "9", "6");
 
rsort($array, SORT_NATURAL);
 
print_r($array);
 
 
 
 
/*
run:
 
Array
(
    [0] => 55
    [1] => 9
    [2] => 8
    [3] => 7
    [4] => 6
    [5] => 0
)

*/

 



answered Sep 3, 2022 by avibootz
0 votes
$array = array("7", "0", "55", "8", "9", "6");
 
natsort($array);

$array = array_reverse($array);
 
print_r($array);
 
 
 
 
/*
run:
 
Array
(
    [0] => 55
    [1] => 9
    [2] => 8
    [3] => 7
    [4] => 6
    [5] => 0
)

*/

 



answered Sep 3, 2022 by avibootz

Related questions

...