In this tutorial we will learn How to Sort an array in ascending order in PHP, We can use PHP sort() Function for this, a built-in function made to sort arrays in ascending order.
Table of Contents
PHP sort() function
PHP sort() function sorts indexed or numeric array in ascending order.
sort() function takes two things as a parameter, an array and the value to define the sorttype.
The sort() function returns 1 after sorting the array.
Sorting array in ascending numerical order
<?php
$array=array(4,2,5,1,3);
sort($array);
print_r($array);
?>
Sorting array in ascending alphabetical order
<?php
$array=array("Orange","Mango","Apple","Watermelon","Strawberry");
sort($array);
print_r($array);
?>