Account
Categories

sort()


When you use sort() on an array, it arranges the values in ascending order or descending order.

The values can be numbers or strings. By default, it sorts the values in ascending order if you don’t specify the order.

It works only with an indexed array.

Syntax:

sort($array_name);

Example:

$numbers = array(50, 10, 30, 20);
sort($numbers);
print_r($numbers);

Output:

Array
(
    [0] => 10
    [1] => 20
    [2] => 30
    [3] => 50
)