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:
- 区分大小写吗?(
strcmpvsstrcasecmp,strnatcmpvsstrnatcasecmp) - 取决于语言环境?(
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 7.4 在写入变量中的 Twig 问题 2022-01-01
- 将变量从树枝传递给 js 2022-01-01
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
- Web 服务器如何处理请求? 2021-01-01
- php中的foreach复选框POST 2021-01-01
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- php中的PDF导出 2022-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
