How to sort an array of numbers in ascending order by first digit in PHP

1 Answer

0 votes
$arr = array(11, 32, 17, 42, 13, 100, 25, 92, 91);

sort($arr, SORT_STRING);

print_r($arr);


/*
run:

Array
(
    [0] => 100
    [1] => 11
    [2] => 13
    [3] => 17
    [4] => 25
    [5] => 32
    [6] => 42
    [7] => 91
    [8] => 92
)

*/

 



answered Mar 28, 2021 by avibootz

Related questions

...