duandang2838 2017-08-05 08:23
浏览 54
已采纳

删除两个使用数组函数不存在的键后比较2个数组

I have 2 arrays a and b which may or may not have similar values.

$a = array('id' => 1, 'name' => 'John Doe', 'age' => 35);
$b = array('name' => 'John Doe', 'age' => 35);

I need to check whether the keys that are there in both the arrays contains same values or not using the array functions itself. Please help me.

NB: Array $a is always the parent array. If any key has to be popped, it would be only from $a.

  • 写回答

4条回答 默认 最新

  • duanhe6799 2017-08-05 08:38
    关注

    You can use the following comparison based on array_intersect_assoc:

    $b == array_intersect_assoc($a, $b)
    

    This will be true when all of the $b key/value pairs occur in $a, false otherwise.

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

报告相同问题?

悬赏问题

  • ¥15 为啥画版图在Run DRC会出现Connect Error?可我Calibre的hostname和计算机的hostname已经设置成一样的了。
  • ¥20 网站后台使用极速模式非常的卡
  • ¥20 Keil uVision5创建project没反应
  • ¥15 mmseqs内存报错
  • ¥15 vika文档如何与obsidian同步
  • ¥15 华为手机相册里面的照片能够替换成自己想要的照片吗?
  • ¥15 陆空双模式无人机飞控设置
  • ¥15 sentaurus lithography
  • ¥100 求抖音ck号 或者提ck教程
  • ¥15 关于#linux#的问题:子进程1等待子进程A、B退出后退出(语言-c语言)