doudao1282 2017-01-25 08:09
浏览 247
已采纳

如何检查多维数组中是否存在某些索引的重复值?

My problem is i have a multidimensional array posting from form to php, now i want to checking if duplicate values of some indexes exist in multi dimensional array or not? e.g:

$data=Array
(
    0 => Array
    (
        uid => '100',
        name => 'Sandra Shush',
        type => 'abc'
    ),
    1 => Array
    (
        uid  => '101',
        name => 'Sandra Shushtext',
        type => 'xyz'
    ),
    2 => Array
    (
        uid => '100',
        name => 'Sandra Shush',
        type => 'abc'
    )
);

here name and type of index 1 and 2 are same, so how can i check it?

I am familiar with

$key = array_search('abc', array_column($data, 'type'));

but it is for duplication of single column value in multi rows, in my situation if multi column of same rows same with multi column of any other row then record will be consider as duplicate.

Any help should be appreciated, Thanks in advance.

  • 写回答

4条回答 默认 最新

  • douyan4470 2017-01-27 09:14
    关注

    I achieved above scenario like this:

    Dont know which one is best mine or other's who posted answers.

    foreach($data as $key => $row)
    {
        $combinedarr[] = array("name"=>$row["name"],"type"=>$row["type"]);
    }
    //chck if same facilitiy is being visit on same date twice
    $countcomb = count($combinedarr);
    $uniquearr = array_unique($combinedarr, SORT_REGULAR);
    if($countcomb==count($uniquearr)){
    }else{
        //yes duplicate exists
    };
    

    Thanks again for those who answered.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失