uksort

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

&reftitle.description; `true` `uksort` `array` `array` `callable` `callback`

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

¬e.sort-unstable; ¬e.reset-index;
&reftitle.parameters;

`array`

- The input array.

`callback`

- &sort.callback.description;
&reftitle.returnvalues;

&return.true.always;

&reftitle.changelog;

&Version; | &Description;
&return.type.true; &array.changelog.by-ref;

&reftitle.examples;

### `uksort` 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";
    }
    ?>

&example.outputs;

    an apple: 3
    a banana: 4
    the Earth: 2
    John: 1

&reftitle.seealso;

- `usort`
- `uasort`
- &seealso.array.sorting;