strnatcmp区分字母大小写php,PHP strnatcmp()用法及代码示例

strnatcmp()是PHP上的内置函数。此函数使用“natural order”算法比较两个字符串,并返回正整数,负数或零。此功能区分大小写。

用法:

strnatcmp( $string1, $string2 )

参数:该函数接受两个强制字符串参数进行比较,如上面的语法所示。

$string1:此参数指定要比较的第一个字符串。

$string 2:此参数指定要比较的第一个字符串。

返回值:该函数根据以下条件返回整数值:

如果两个字符串相等,则该函数返回0。

函数返回负值(

如果$string2小于$string1,则函数返回正值(> 0)。

例子:

Input : $string1 = "Hello", $string2 = "HEllo"

Output : 1

Input : $string1 = "Geek", $string2 = "Geeks"

Output : -1

以下示例程序旨在说明PHP中的strnatcmp()函数:

程序1:该程序显示了strnatcmp()函数的简单用法。

echo strnatcmp("Geek", "Geeks");

?>

输出:

-1

程序2:该程序显示strnatcmp()函数的区分大小写。

echo strnatcmp("Geeks", "GEEks");

?>

输出:

1

程序3:此程序说明了strcmp()和strnatcmp()函数之间的区别。

echo strnatcmp("Geek of month 2", "Geek of month 10");

echo "\n";

echo strcmp("Geek of month 2", "Geek of month 10");

?>

输出:

-1

256

Explanation :In a natural algorithm, the number 2 is less than the number 10 whereas in computer sorting, 10 is considered to be less than 2 as the first number in “10” is less than 2.

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值