douzhengyi5022 2016-02-05 10:37
浏览 30
已采纳

通过值从三个数组中获得差异

I am trying to get the difference between three arrays

array_diff() function doesn't help because it matches only the first array with others

For example I want to compare three arrays and each array has one of the element different from each other like this

$a1=array("a"=>"red","b"=>"green","c"=>"blue", 'v1' => 'sss');
$a2=array("e"=>"red","f"=>"green","g"=>"blue", 'v2' => 'ss');
$a3=array("e"=>"red","f"=>"green","g"=>"blue", 'v3' => 's');

when I use array_diff() on these arrays it would just show me the unique value out of other two arrays

$res = array_diff($a1, $a2, $a3);

print_r($res);

It's result would be Array ( [v1] => sss )

While I want it to tell me the unique values in all these arrays like this Array ( [v1] => sss [v2] => ss [v3] => s )

I tried other array comparison functions but couldn't find one to compare all given array to each other instead of comparing just one array to others

  • 写回答

1条回答 默认 最新

  • dongxian6653 2016-02-05 11:28
    关注
        $var=(array_diff($a1,$a2,$a3));
        $var1=(array_diff($a2,$a1,$a3));
        $var2=(array_diff($a3,$a2,$a1));
        $v=array_merge($var,$var1,$var2);
    

    I guess this helps for you.check it out..

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?
  • ¥15 讲解电路图,付费求解
  • ¥15 有偿请教计算电磁学的问题涉及到空间中时域UTD和FDTD算法结合的
  • ¥15 three.js添加后处理以后模型锯齿化严重
  • ¥15 vite打包后,页面出现h.createElement is not a function,但本地运行正常