Reputation: 4557
I have two arrays :
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
Upvotes: 0
Views: 74
Reputation: 26153
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 )
Upvotes: 0