PHP.nl

uksort

uksort

Sort an array by keys using a user-defined comparison function

true **uksort** array $array callable $callback

Sorts in place by keys using a user-supplied comparison function to determine the order. array

arrayThe input array.

callback

return.true.always

Voorbeeld: example

<?php
function cmp($a, $b)
{
    $a = preg_replace('@^(a|an|the) @', '', $a);
    $b = preg_replace('@^(a|an|the) @', '', $b);
    return strcasecmp($a, $b);
}

$a = array("John" => 1, "the Earth" => 2, "an apple" => 3, "a banana" => 4);

uksort($a, "cmp");

foreach ($a as $key => $value) {
    echo "$key: $value\n";
}
?>
an apple: 3
a banana: 4
the Earth: 2
John: 1

usort``uasort