PHP 中的 strcmp() 函数

phpprogrammingserver side programming更新于 2025/9/16 21:07:17

strcmp() 函数用于比较两个字符串。

注意 − 此函数区分大小写。

语法

strcmp(str1, str2)

参数

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

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

返回

strcmp() 函数返回 −

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

  • <0 - 如果 string1 小于 string2

  • >0 - 如果 string1 大于 string2

示例

下面是一个例子 −

<?php
   echo strcmp("windows","Windows");
?>

输出

以下是输出 −

32

示例

让我们看另一个例子 −

<?php
   echo strcmp("Windows OS","Windows Operating System");
?>

输出

以下是输出 −

-7424

相关文章