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:为什么需要字符串比较函数?


基础教程推荐
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何替换eregi() 2022-01-01