sort array in reverse in php

To sort an array in reverse order in PHP, you can use the rsort() function. This function sorts the array in descending order.

Here's an example:

main.php
$fruits = array("apple", "orange", "banana", "mango");
rsort($fruits);
print_r($fruits);
89 chars
4 lines

Output:

main.php
Array
(
    [0] => orange
    [1] => mango
    [2] => apple
    [3] => banana
)
80 chars
8 lines

In the above example, we first define an array of fruits. Then we call the rsort() function to sort the array in reverse order. Finally, we use the print_r() function to display the sorted array.

related categories

gistlibby LogSnag