不区分大小写array_unique [英] case-insensitive array_unique

查看:533
本文介绍了不区分大小写array_unique的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写code几行,以不区分大小写的数组类型的独特功能。这是我到目前为止有:

 的foreach($主题为$值){
    $左值=用strtolower($值);
    $ uvalue =用strtolower($值);    如果(in_array($价值$主题)== FALSE || in_array($左值,$主题)== FALSE || in_array($ uvalue,$主题)== FALSE){
        array_push($ utopics,$值);
    }
}

麻烦的是if语句。我觉得有什么毛病我的语法,但我是比较新的PHP和我不知道它是什么。任何帮助吗?


解决方案

 函数array_iunique($数组){
    返回array_intersect_key(
        $阵列,
        array_unique(array_map(用strtolower,$阵列))
    );
}

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);
    }
}

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆