PHPマニュアル/PEARマニュアル | ユーザフォーラムで議論/質問 | マニュアル検索 | ハイライト | ハイライトオフ | ポータル | php spot

Ds\Set::sorted - Returns a sorted copy. | JavaScript入門&応用&リファレンスなら「JavaScriptist」

  

Ds\Set::sorted

(PECL ds >= 1.0.0)

Ds\Set::sortedReturns a sorted copy.

説明

public Ds\Set Ds\Set::sorted ([ callable $comparator ] )

Returns a sorted copy, using an optional comparator function.

パラメータ

comparator

比較関数は、最初の引数と二番目の引数の比較結果を返します。最初の引数のほうが二番目の引数より大きい場合は正の数を、二番目の引数と等しい場合はゼロを、そして二番目の引数より小さい場合は負の数を返す必要があります。PHP 7.0.0 より前のバージョンでは、この整数が -2147483648 から 2147483647 までの範囲におさまる必要がありました。

int callback ( mixed $a, mixed $b )
警告

Returning non-integer values from the comparison function, such as float, will result in an internal cast to integer of the callback's return value. So values such as 0.99 and 0.1 will both be cast to an integer value of 0, which will compare such values as equal.

返り値

Returns a sorted copy of the set.

例1 Ds\Set::sorted() example

<?php
$set 
= new \Ds\Set([45132]);

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([45132]);

$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
)

忘却曲線を使ってこの知識を確実に記憶に残す

フォーラムで「Ds\Set::sorted - Returns a sorted copy.」について話す
各種マニュアル: PHPマニュアル | PEARマニュアル | Smarty(英語)マニュアル | PHP-GTKマニュアル | Ds\Set::sorted - Returns a sorted copy.」をGoogle検索
copyright © 1997-2024 PHP ドキュメント作成グループ(ライセンス). provided by php spot. マニュアル: