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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?