doutong1890 2018-03-27 14:06
浏览 67
已采纳

我应该使用array_diff_assoc还是===?

I'm trying to compare two arrays to see if they are sorted or not. What is the difference between array_diff_assoc and comparing two arrays with the === operator? Are they the same thing?

For example

$arr_a
$arr_b

array_diff_assoc($arr_a, $arr_b)

Is the same as

$arr_a === $arr_b

?

  • 写回答

2条回答 默认 最新

  • dtebrq0245 2018-03-27 14:13
    关注

    Simple example tells us that these are different methods:

    $a = ['t' => 2, 'p' => 3];
    $b = ['p' => 3, 't' => 2];
    var_dump($a === $b); // false, arrays are not identical                
    var_dump(array_diff_assoc($a, $b));  
    // array(0) {} - means that there's no difference between these arrays
    // they have same keys with same values, but in different orders 
    // and for `===` order is important
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了