rsort()
` function to sort an array of numbers in descending numerical order :<?php
// Create an array of numbers
$numbers = array(3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5);
// Sort the array in descending numerical order
rsort($numbers);
// Loop through the sorted array and print the values
foreach($numbers as $number) {
echo $number . "<br>";
}
?>
9
6
5
5
5
4
3
3
2
1
1
$numbers
`. We use the `rsort()
` function to sort the array in descending numerical order. foreach
` loop and the values of each element are printed to the screen.rsort()
` function works by comparing the values of the elements in the array and swapping them if necessary to put them in descending order. By default, it uses a comparison based on the values of the elements themselves. usort()
` function instead.