PHP.nl

sort

sort

Sort an array in ascending order

true **sort** array $array int $flags

Sorts in place by values in ascending order. array

arrayThe input array.

return.true.always

Voorbeeld: example

<?php

$fruits = array("lemon", "orange", "banana", "apple");
sort($fruits);
foreach ($fruits as $key => $val) {
    echo "fruits[" . $key . "] = " . $val . "\n";
}

?>
fruits[0] = apple
fruits[1] = banana
fruits[2] = lemon
fruits[3] = orange

The fruits have been sorted in alphabetical order.

Voorbeeld: example using case-insensitive natural ordering

<?php

$fruits = array(
    "Orange1", "orange2", "Orange3", "orange20"
);
sort($fruits, SORT_NATURAL | SORT_FLAG_CASE);
foreach ($fruits as $key => $val) {
    echo "fruits[" . $key . "] = " . $val . "\n";
}

?>
fruits[0] = Orange1
fruits[1] = orange2
fruits[2] = Orange3
fruits[3] = orange20

The fruits have been sorted like . natcasesort

Opmerking: > Like most PHP sorting functions, uses an implementation of . 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. sortQuicksort

Waarschuwing: > Be careful when sorting arrays with mixed types values because can produce unexpected results, if is . sort``flags``SORT_REGULAR

rsort