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 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器