Php/docs/collator.compare

提供:Dev Guides
< Php
移動先:案内検索

Collator::compare

collator_compare

(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)

Collator::compare -- collator_compareふたつの Unicode 文字列を比較する


説明

オブジェクト指向型

public Collator::compare ( string $str1 , string $str2 ) : int

手続き型

collator_compare ( Collator $coll , string $str1 , string $str2 ) : int

ふたつの Unicode 文字列を、比較規則にもとづいて比較します。


パラメータ

coll
Collator オブジェクト。
str1
最初の文字列。
str2
2 番目の文字列。


返り値

比較結果を返します。

  • str1str2 より 大きい ときは 1
  • str1str2等しい ときは 0
  • str1str2 より 小さい ときは -1

エラー時には bool false を返します。

警告 この関数は論理値 false を返す可能性がありますが、false として評価される値を返す可能性もあります。 詳細については 論理値の セクションを参照してください。この関数の返り値を調べるには ===演算子 を 使用してください。


例1 collator_compare() の例

<?php$s1 = 'Hello';$s2 = 'hello';$coll = collator_create( 'en_US' );$res  = collator_compare( $coll, $s1, $s2 );if ($res === false) {    echo collator_get_error_message( $coll );} else if( $res > 0 ) {    echo "s1 is greater than s2\n";} else if( $res < 0 ) {    echo "s1 is less than s2\n";} else {    echo "s1 is equal to s2\n";}?>

上の例の出力は以下となります。


s1 is greater than s2

参考