PHP中的strcoll()函数

strcoll()函数用于根据语言环境比较两个字符串。

注意-此功能区分大小写

语法

strcoll(str1, str2)

参数

  • str1-要比较的第一个字符串

  • str2-要比较的第二个字符串

返回

strcoll()函数返回-

  • 0-如果两个字符串相等

  • <0-如果string1小于string2

  • > 0-如果string1大于string2

示例

以下是一个例子-

<?php
   setlocale (LC_COLLATE, 'en_US'); 
   echo strcoll("Demo text!","Demo text!");
?>

输出结果

0

示例

以下是一个例子-

<?php
   $x = 'a'; $y = 'A';
   setlocale (LC_COLLATE, 'de_CH'); 
   print "de_CH: " . strcoll ($x, $y) . "\n";
?>

输出结果

de_CH: 32