The sort Function
The sort function sorts an array
in ascending order by its elements.
The function modifies the array itself.
Syntax
sort(array &$array, int $flags = SORT_REGULAR): bool
Example
Let's sort an array in ascending order by its elements:
<?php
$arr = [1, 3, 2, 5, 4];
sort($arr);
var_dump($arr);
?>
The code execution result:
[1, 2, 3, 4, 5]
See Also
-
the
rsortfunction,
which sorts in descending order by elements -
the
ksortfunction,
which sorts in ascending order by keys -
the
krsortfunction,
which sorts in descending order by keys -
the
asortfunction,
which sorts in ascending order by elements with key preservation -
the
arsortfunction,
which sorts in descending order by elements with key preservation -
the
natsortfunction,
which sorts using natural order -
the
natcasesortfunction,
which sorts using natural order case-insensitively -
the
usortfunction,
which sorts using a callback function -
the
uksortfunction,
which sorts by keys using a callback function -
the
uasortfunction,
which sorts using a callback function with key preservation -
the
array_multisortfunction,
which sorts multiple arrays