array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'ja', ), 'this' => array ( 0 => 'ds-set.sorted.php', 1 => 'Ds\\Set::sorted', ), 'up' => array ( 0 => 'class.ds-set.php', 1 => 'Ds\\Set', ), 'prev' => array ( 0 => 'ds-set.sort.php', 1 => 'Ds\\Set::sort', ), 'next' => array ( 0 => 'ds-set.sum.php', 1 => 'Ds\\Set::sum', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/ds/ds/set/sorted.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PECL ds >= 1.0.0)
Ds\Set::sorted — Returns a sorted copy
Returns a sorted copy, using an optional comparator
function.
comparator
比較関数は、最初の引数と二番目の引数の比較結果を返します。最初の引数のほうが二番目の引数より大きい場合は正の整数を、二番目の引数と等しい場合はゼロを、そして二番目の引数より小さい場合は負の整数を返す必要があります。
Returns a sorted copy of the set.
例1 Ds\Set::sorted() example
<?php
$set = new \Ds\Set([4, 5, 1, 3, 2]);
print_r($set->sorted());
?>
上の例の出力は、 たとえば以下のようになります。
Ds\Set Object ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 )
例2 Ds\Set::sorted() example using a comparator
<?php
$set = new \Ds\Set([4, 5, 1, 3, 2]);
$sorted = $set->sorted(function($a, $b) {
return $b <=> $a;
});
print_r($sorted);
?>
上の例の出力は、 たとえば以下のようになります。
Ds\Set Object ( [0] => 5 [1] => 4 [2] => 3 [3] => 2 [4] => 1 )