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

2 Answers

0 votes
$array = array("7", "0", "55", "8", "9", "6");

sort($array, SORT_NATURAL);

print_r($array);




/*
run:

Array
(
    [0] => 0
    [1] => 6
    [2] => 7
    [3] => 8
    [4] => 9
    [5] => 55
)

*/

 



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

natsort($array);

print_r($array);




/*
run:

Array
(
    [0] => 0
    [1] => 6
    [2] => 7
    [3] => 8
    [4] => 9
    [5] => 55
)

*/

 



answered Sep 2, 2022 by avibootz

Related questions

...