dqu92800 2012-02-02 17:35
浏览 140
已采纳

array_udiff_assoc和array_diff_uassoc之间的区别是什么?

what is the difference between array_udiff_assoc and array_diff_uassoc

for array_udiff_assoc i get this thing

<?php
 function myfunction($v1,$v2)
 {
 if ($v1===$v2)
   {
   return 0;
   }
 return 1;
 }
 $a1=array("a"=>"Cat","b"=>"Dog","c"=>"Horse");
 $a2=array("a"=>"Cat","b"=>"Horse","c"=>"Dog");
 print_r(array_udiff_assoc($a1,$a2,"myfunction"));
 ?>

result

Array ( [b] Dog [c] => Horse )

also array_diff_uassoc

  <?php
     function myfunction($v1,$v2)
     {
     if ($v1===$v2)
       {
       return 0;
       }
     return 1;
     }
     $a1=array("a"=>"Cat","b"=>"Dog","c"=>"Horse");
     $a2=array("a"=>"Cat","b"=>"Horse","c"=>"Dog");
     print_r(array_diff_uassoc($a1,$a2,"myfunction"));
     ?>

result is same as first one

Array ( [b] Dog [c] => Horse )

Is the have any difference, if have what is that. Php manual does not says that they are alias, as they used to say.

  • 写回答

2条回答 默认 最新

  • doulianqi3870 2012-02-02 17:43
    关注

    They both do the same, but udiff-assoc compares the DATA with the user supplied function, while diff-uassoc compares the INDEX with the user supplied function.

    As an answer to @lonsesomeday : as indicated by the 'u', diff_assoc will use internal functions for all comparisons, and udiff_uassoc uses provided callbacks for index and data comparison.

    http://www.php.net/manual/en/function.array-diff-uassoc.php

    http://www.php.net/manual/en/function.array-udiff-assoc.php

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

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集