doushifang4382 2014-04-22 16:51
浏览 543
已采纳

如何删除另一个数组中包含的数组元素

I have an array like

<?php
 $array1 = array(1,2,3,5);
 $array2 = array(1,3,4,5,6,7);

?> 

i want $array3 to look like

 $array3 = array(4,6,7);

In simple words remove elements of $array2 if contained in $array1 i am a newbie searched a lot but didnt found anything.Help would be thanked.

  • 写回答

1条回答 默认 最新

  • dongxia2030 2014-04-22 16:53
    关注

    Use array_diff():

    $result = array_diff($array2, $array1);
    

    Note that the order of arguments is important here. The above statement checks $array2 against $array1 and returns the values in $array2 that are not present in $array1.

    Output:

    Array
    (
        [2] => 4
        [4] => 6
        [5] => 7
    )
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度