不区分大小写的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 ) )
);
}