Collator
PHP Manual

Collator::compare

collator_compare

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

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

説明

オブジェクト指向型

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

手続き型

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

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

パラメータ

coll

Collator オブジェクト。

str1

最初の文字列。

str2

2 番目の文字列。

返り値

比較結果を返します。

エラー時には boolean 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

参考


Collator
PHP Manual