duaner1634 2015-07-02 10:07
浏览 85
已采纳

删除第二个数组中存在的数组元素

I have two arrays :

  1. Array Dates
   Array
    (
        [0] => 2015-07-02
        [1] => 2015-07-03
        [2] => 2015-07-04
        [3] => 2015-07-05
        [4] => 2015-07-06
        [5] => 2015-07-07
        [6] => 2015-07-08
        [7] => 2015-07-09
        [8] => 2015-07-10
        [9] => 2015-07-11
        [10] => 2015-07-12
        [11] => 2015-07-13
        [12] => 2015-07-14
        [13] => 2015-07-15
        [14] => 2015-07-16
        [15] => 2015-07-17
        [16] => 2015-07-18
        [17] => 2015-07-19
        [18] => 2015-07-20
        [19] => 2015-07-21
        [20] => 2015-07-22
        [21] => 2015-07-23
        [22] => 2015-07-24
        [23] => 2015-07-25
        [24] => 2015-07-26
        [25] => 2015-07-27
        [26] => 2015-07-28
        [27] => 2015-07-29
        [28] => 2015-07-30
        [29] => 2015-07-31
        [30] => 2015-08-01
    )

2- Array Finald

>

 Array (
>     [0] => 2015-07-07
>     [1] => 2015-07-14
>     [2] => 2015-07-21
>     [3] => 2015-07-28
>     [4] => 2015-08-04
>     [5] => 2015-08-11
>     [6] => 2015-08-18
>     [7] => 2015-08-25
>     [8] => 2015-09-01
>     [9] => 2015-09-08
>     [10] => 2015-09-15
>     [11] => 2015-09-22
>     [12] => 2015-09-29
>     [13] => 2015-10-06
>     [14] => 2015-10-13
>     [15] => 2015-10-20
>     [16] => 2015-10-27
>     [17] => 2015-11-03
>     [18] => 2015-11-10
>     [19] => 2015-11-17
>     [20] => 2015-11-24
>     [21] => 2015-07-16
>     [22] => 2015-07-23
>     [23] => 2015-07-30
>     [24] => 2015-08-06
>     [25] => 2015-08-13
>     [26] => 2015-08-20
>     [27] => 2015-08-27
>     [28] => 2015-09-03
>     [29] => 2015-09-10
>     [30] => 2015-09-17
>     [31] => 2015-09-24
>     [32] => 2015-10-01
>     [33] => 2015-10-08
>     [34] => 2015-10-15
>     [35] => 2015-10-22
>     [36] => 2015-10-29
>     [37] => 2015-11-05
>     [38] => 2015-11-12
>     [39] => 2015-11-19
>     [40] => 2015-11-26
>     [41] => 2015-12-03 )

I want to remove elements from array dates which are not present in finald array. I am using the following code :

$tags = array_diff($dates, $finald);

I am getting the following array

Array
(
    [0] => 2015-07-02
    [1] => 2015-07-03
    [2] => 2015-07-04
    [3] => 2015-07-05
    [4] => 2015-07-06
    [6] => 2015-07-08
    [7] => 2015-07-09
    [8] => 2015-07-10
    [9] => 2015-07-11
    [10] => 2015-07-12
    [11] => 2015-07-13
    [13] => 2015-07-15
    [15] => 2015-07-17
    [16] => 2015-07-18
    [17] => 2015-07-19
    [18] => 2015-07-20
    [20] => 2015-07-22
    [22] => 2015-07-24
    [23] => 2015-07-25
    [24] => 2015-07-26
    [25] => 2015-07-27
    [27] => 2015-07-29
    [29] => 2015-07-31
    [30] => 2015-08-01
    [5] => 2015-07-06
    [12] => 2015-07-13
    [14] => 2015-07-15
    [19] => 2015-07-20
    [21] => 2015-07-22
)

I am not getting Why 16-07-2015 and 23-07-2015 is removed from the final tags array

  • 写回答

2条回答 默认 最新

  • douningle7944 2015-07-02 10:21
    关注

    remove elements from array dates which are not present in finald

    So, save that are in both arrays?

    $dates = Array
        (
            '2015-07-02',        
            '2015-07-03');
    $finald =  array(
            '2015-07-02',        
            '2015-07-07');
    print_r(array_intersect($dates, $finald));   
    

    result

    Array ( [0] => 2015-07-02 ) 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料