sortSort an array in ascending order
&reftitle.description;
boolsortarrayarrayintflagsSORT_REGULAR
Sorts array in place by values
in ascending order.
¬e.sort-unstable;
¬e.no-key-association;
&reftitle.parameters;
array
The input array.
&sort.flags.parameter;
&reftitle.returnvalues;
&return.true.always;
&reftitle.examples;
sort example
$val) {
echo "fruits[" . $key . "] = " . $val . "\n";
}
?>
]]>
&example.outputs;
The fruits have been sorted in alphabetical order.
sort example using case-insensitive natural
ordering
$val) {
echo "fruits[" . $key . "] = " . $val . "\n";
}
?>
]]>
&example.outputs;
The fruits have been sorted like natcasesort.
&reftitle.notes;
Like most PHP sorting functions, sort uses an
implementation of Quicksort.
The pivot is chosen in the middle of the partition resulting in an optimal
time for already sorted arrays. This is however an implementation detail you
shouldn't rely on.
Be careful when sorting arrays with mixed types values because
sort can produce unexpected results,
if flags is SORT_REGULAR.
&reftitle.seealso;
rsort&seealso.array.sorting;