Sort() function is used to sort array in ascending order.
Example:
<?php
$numbers = array(9, 6, 3, 22, 12);
sort($numbers);
$length = count($numbers);
for($x = 0; $x < $length; $x++) {
echo $numbers[$x];
echo "<br>";
}
?>
Output : 3, 6, 9, 12 , 22
rsort() function is used to sort Array in descending order
Example:
<?php
$numbers = array(9, 6, 3, 22, 12);
rsort($numbers);
$length = count($numbers);
for($x = 0; $x < $length; $x++) {
echo $numbers[$x];
echo "<br>";
}
?>
Output : 22, 12, 9, 6, 3
0 Comment(s)