Ds\Map::sorted

Returns a copy, sorted by value

&reftitle.description; public `Ds\Map` `Ds\Map::sorted` `callable` `comparator`

Returns a copy, sorted by value using an optional `comparator` function.

&reftitle.parameters;

`comparator`

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

Returns a copy of the map, sorted by value.

&reftitle.examples;

### `Ds\Map::sort` example

    <?php
    $map = new \Ds\Map(["a" => 2, "b" => 3, "c" => 1]);

    print_r($map->sorted());
    ?>

&example.outputs.similar;

    Ds\Map Object
    (
        [0] => Ds\Pair Object
            (
                [key] => c
                [value] => 1
            )

        [1] => Ds\Pair Object
            (
                [key] => a
                [value] => 2
            )

        [2] => Ds\Pair Object
            (
                [key] => b
                [value] => 3
            )

    )

### `Ds\Map::sort` example using a comparator

    <?php
    $map = new \Ds\Map(["a" => 2, "b" => 3, "c" => 1]);

    // Reverse
    $sorted = $map->sorted(function($a, $b) {
        return $b <=> $a;
    });

    print_r($sorted);
    ?>

&example.outputs.similar;

    Ds\Map Object
    (
        [0] => Ds\Pair Object
            (
                [key] => b
                [value] => 3
            )

        [1] => Ds\Pair Object
            (
                [key] => a
                [value] => 2
            )

        [2] => Ds\Pair Object
            (
                [key] => c
                [value] => 1
            )

    )