PHP不区分大小写数组搜索函数[duplicate]
16lz
2021-01-22
Possible Duplicate:
PHP case-insensitive in_array function可能重复:PHP不区分大小写的in_array函数
Is it possible to do case-insensitive comparison when using the in_array
function?
是否可以在使用in_array函数时进行不区分大小写的比较?
So with a source array like this:
这样一个源数组
$a= array(
'one',
'two',
'three',
'four'
);
The following lookups would all return true:
以下查找都将返回true:
in_array('one', $a);
in_array('ONE', $a);
in_array('fOUr', $a);
What function or set of functions would do the same? I don't think in_array
itself can do this. Because it is case sensitive.
哪个函数或函数集会做同样的事情?我不认为in_array本身可以做到这一点。因为它是区分大小写的。
1 个解决方案
#1
6
If you want to apply strtolower on each element of the array, use array_map:
如果要在数组的每个元素上应用strtolower,请使用array_map:
in_array(strtolower('ONE'), array_map('strtolower', $a));
in_array(函数(“一”),到(“函数”,一个美元));
更多相关文章
- [轉]PHP官方网站,php官方论坛,中文函数手册下载
- php image函数,操作压缩图片时,png图片压缩后整个图片变黑
- PHP中钩子函数的实现与认识
- 如何通过.click jQuery函数检索html元素值与从MySQL检索的数据?
- 几个有用的php字符串过滤,转换函数代码
- PHP空间函数类似于ASP空间()
- PHP中类和对象的相关函数
- php函数 什么时候使用fflush函数
- 如何调试UPDATE函数在PHP中无法正常工作的原因?