How to sort an array of numbers in PHP

How to sort an array of numbers in PHP

In this post we will give you information about How to sort an array of numbers in PHP. Hear we will give you detail about How to sort an array of numbers in PHPAnd how to use it also give you demo for it if it is necessary.

In this example, you will learn about how to sort an array of numbers both ascending and descending order in PHP.

Sorting numbers in ascending order

<!DOCTYPE html><html><body><?php$numbers = array(2, 45, 1, 3, 5);sort($numbers); // ascending order$arrlength = count($numbers);for($x = 0; $x < $arrlength; $x++) {    echo $numbers[$x];    echo "<br>";}?></body></html>

Ouput:

123545

Sorting numbers in descending order

<!DOCTYPE html><html><body><?php$numbers = array(2, 45, 1, 3, 5);rsort($numbers); // descending order$arrlength = count($numbers);for($x = 0; $x < $arrlength; $x++) {    echo $numbers[$x];    echo "<br>";}?></body></html>

Output:

455321

Hope this code and post will helped you for implement How to sort an array of numbers in PHP. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US