@@ 507-519 (lines=13) @@ | ||
504 | * |
|
505 | * @param callable|null $comparator Accepts two values to be compared. |
|
506 | */ |
|
507 | public function sort(callable $comparator = null) |
|
508 | { |
|
509 | if ($comparator) { |
|
510 | usort($this->pairs, function($a, $b) use ($comparator) { |
|
511 | return $comparator($a->value, $b->value); |
|
512 | }); |
|
513 | ||
514 | } else { |
|
515 | usort($this->pairs, function($a, $b) { |
|
516 | return $a->value <=> $b->value; |
|
517 | }); |
|
518 | } |
|
519 | } |
|
520 | ||
521 | /** |
|
522 | * Returns a sorted copy of the map, based on an optional callable |
|
@@ 543-555 (lines=13) @@ | ||
540 | * |
|
541 | * @param callable|null $comparator Accepts two keys to be compared. |
|
542 | */ |
|
543 | public function ksort(callable $comparator = null) |
|
544 | { |
|
545 | if ($comparator) { |
|
546 | usort($this->pairs, function($a, $b) use ($comparator) { |
|
547 | return $comparator($a->key, $b->key); |
|
548 | }); |
|
549 | ||
550 | } else { |
|
551 | usort($this->pairs, function($a, $b) { |
|
552 | return $a->key <=> $b->key; |
|
553 | }); |
|
554 | } |
|
555 | } |
|
556 | ||
557 | /** |
|
558 | * Returns a sorted copy of the map, based on an optional callable |