To sort an array in PHP, you can use one of the many built-in sorting functions. Here are a few examples:
Sorting an indexed array in ascending order based on its values using sort():
main.php87 chars4 lines
Output:
main.php79 chars8 lines
Sorting an indexed array in descending order based on its values using rsort():
main.php87 chars4 lines
Output:
main.php154 chars15 lines
Sorting an associative array in ascending order based on its keys using ksort():
main.php77 chars4 lines
Output:
main.php60 chars7 lines
There are many other sorting functions available in PHP, such as asort(), arsort(), and uasort(), each with its own specific use case.
gistlibby LogSnag