-2

I have problem in multidimensional array I have a PHP array as follows:

$array1 = array( 
1 => '01-Jul-2017',
2 => '02-Jul-2017',
3 => '03-Jul-2017',
4 => '04-Jul-2017',
5 => '05-Jul-2017',
...,
31 => '31-Jul-2017',);

$array2 = array( 
1 => '01-Jul-2017',
3 => '03-Jul-2017',
4 => '04-Jul-2017',
5 => '05-Jul-2017',
6 => '06-Jul-2017',
...,
30 => '31-Jul-2017');

foreach($array1 as $array_one) {
    foreach($array2 as $array_two) {
        if($array_one == $array_two) {
            echo 'write';
        } else {
            **I want to display that does not exist in $ array2 output 02-Jul-2017;**
        }
    }
}

How do i get just the value 02-Jul-2017

ibez
  • 11
  • 2

1 Answers1

1

You can use array_diff() inbuilt function.

$array1 = array( 
1 => '01-Jul-2017',
2 => '02-Jul-2017',
3 => '03-Jul-2017',
4 => '04-Jul-2017',
5 => '05-Jul-2017');

$array2 = array( 
1 => '01-Jul-2017',
3 => '03-Jul-2017',
4 => '04-Jul-2017',
5 => '05-Jul-2017',
6 => '06-Jul-2017');

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

OUTPUT

Array ( [2] => 02-Jul-2017 )

Let me know if it not works.

Alex Mac
  • 2,970
  • 1
  • 22
  • 39