(PECL ds >= 1.0.0)
Ds\Map::sort — Sorts the map in-place by value
Sorts the map in-place by value, using an optional comparator
function.
comparator
锟节碉拷一锟斤拷锟斤拷锟斤拷小锟节o拷锟斤拷锟节伙拷锟斤拷诘诙锟斤拷锟斤拷锟斤拷锟绞憋拷锟斤拷帽冉虾锟斤拷锟斤拷锟斤拷锟斤拷锟接︼拷胤锟斤拷锟揭伙拷锟叫★拷冢锟斤拷锟斤拷诨锟斤拷锟斤拷 0 锟斤拷锟斤拷锟斤拷锟斤拷
没锟叫凤拷锟斤拷值锟斤拷
Example #1 Ds\Map::sort() example
<?php
$map = new \Ds\Map(["a" => 2, "b" => 3, "c" => 1]);
$map->sort();
print_r($map);
?>
锟斤拷锟斤拷锟斤拷锟教碉拷锟斤拷锟斤拷锟斤拷锟斤拷冢锟�
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 ) )
Example #2 Ds\Map::sort() example using a comparator
<?php
$map = new \Ds\Map(["a" => 2, "b" => 3, "c" => 1]);
$map->sort(function($a, $b) {
return $b <=> $a;
});
print_r($map);
?>
锟斤拷锟斤拷锟斤拷锟教碉拷锟斤拷锟斤拷锟斤拷锟斤拷冢锟�
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 ) )