phparrayssortingnatural-sort

Sort an array of URLs containing pagination numbers in a descending direction


I need to reorder an array in PHP.

The array:

Array
(
    [0] => /riado/?p=1
    [1] => /riado/?p=2
    [2] => /riado/?p=3
    [3] => /riado/?p=4
)

How to reorder to:

Array
(
    [0] => /riado/?p=4
    [1] => /riado/?p=3
    [2] => /riado/?p=2
    [3] => /riado/?p=1
)

I have searched but I can't find much clues. Can you give me some clues on how to achieve this?


Solution

  • $array = array_reverse($array);
    

    Will reverse the contents of $array, no matter the sort order of the contents.

    rsort($array);
    

    Will sort the array in reverse alphabetical order.