How to Sort Numbers of an Array in Ascending Order in PHP

PHP


In this article, we show how to sort numbers of an array in ascneding order in PHP.

To sort an array of numbers in ascending order in PHP, we use the sort() function.

Let's say we have the array of numbers below:

$numbers= array(48, 93, 4, 6, 21, 11, 32, 17);

And now we want this array to be shown and ordered in ascending order numerically.

We use the sort() function to put it in ascending order.

The general form to put an array of numbers in ascending order:

sort($array_name);

where $array_name is the name of the array we want to sort in ascending order numerically.

For the above array we created, the code to put it in ascending order is:

sort($numbers);

PHP Output

93 48 32 21 17 11 6 4

HTML Comment Box is loading comments...