不区分大小写的array_unique [英] case-insensitive array_unique
本文介绍了不区分大小写的array_unique的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试编写几行代码来制作不区分大小写的数组唯一类型函数.这是我到目前为止所拥有的:
I'm trying to write a few lines of code to make a case insensitive array unique type function. Here's what I have so far:
foreach ($topics as $value) {
$lvalue = strtolower($value);
$uvalue = strtolower($value);
if (in_array($value, $topics) == FALSE || in_array($lvalue, $topics) == FALSE || in_array($uvalue, $topics) == FALSE) {
array_push($utopics, $value);
}
}
问题在于 if 语句.我认为我的语法有问题,但我对 PHP 比较陌生,我不确定它是什么.有什么帮助吗?
The trouble is the if statement. I think there's something wrong with my syntax, but I'm relatively new to PHP and I'm not sure what it is. Any help?
推荐答案
function array_iunique( $array ) {
return array_intersect_key(
$array,
array_unique( array_map( "strtolower", $array ) )
);
}
这篇关于不区分大小写的array_unique的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文