(PECL ds >= 1.0.0)
Ds\Vector::sort — Sorts the vector in-place
Sorts the vector in-place, using an optional comparator function.
comparator比較関数は、最初の引数と二番目の引数の比較結果を返します。最初の引数のほうが二番目の引数より大きい場合は正の整数を、二番目の引数と等しい場合はゼロを、そして二番目の引数より小さい場合は負の整数を返す必要があります。
値を返しません。
例1 Ds\Vector::sort() example
<?php
$vector = new \Ds\Vector([4, 5, 1, 3, 2]);
$vector->sort();
print_r($vector);
?>上の例の出力は、 たとえば以下のようになります。
Ds\Vector Object
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
)
例2 Ds\Vector::sort() example using a comparator
<?php
$vector = new \Ds\Vector([4, 5, 1, 3, 2]);
$vector->sort(function($a, $b) {
return $b <=> $a;
});
print_r($vector);
?>上の例の出力は、 たとえば以下のようになります。
Ds\Vector Object
(
[0] => 5
[1] => 4
[2] => 3
[3] => 2
[4] => 1
)