PHP: Why do we need string comparison function?(PHP:为什么需要字符串比较函数?)
问题描述
比较运算符 <<= >>=
也可以应用于字符串.那么为什么我们需要特殊的字符串比较函数:strcmp
?
The comparision operators < <= > >=
can be applied for strings as well. So why do we need special function for string comparision: strcmp
?
推荐答案
因为有几种变体:
根据功能,这些问题的答案各不相同:
Depending on the function, the answer to these questions vary:
- 区分大小写吗?(
strcmp
vsstrcasecmp
,strnatcmp
vsstrnatcasecmp
) - 取决于语言环境?(
strcoll
会) - 我可以指定排序规则吗?(
strcoll
受setlocale
影响)
此外,比较运算符还给出 true
或 false
.strcmp
给出一个整数,因此它可以同时编码是否存在身份(返回 0),或者如果没有,则更大(取决于值是正数还是负数).
Additionaly, the comparison operators also give true
or false
. strcmp
gives an integer so it can encode simultaneously whether there's identity (return 0) or, if it not, which is is bigger (depending on whether the value is positive or negative).
这篇关于PHP:为什么需要字符串比较函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP:为什么需要字符串比较函数?


- 带有通配符的 Laravel 验证器 2021-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- Laravel 仓库 2022-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01