0

My first array A is : ["1604","1606","1610"]

My second Array B is : ["1604","1606","1607","1610"]

But when i am executing :

   $results= array_diff($b,$a);

then I got the result like this But i dont want association (i.e. 2 as below). I want only key.(i.e. 1607).

My output Array results is : {"2":"1607"}

I want output like ["1607"].

jh314
  • 27,144
  • 16
  • 62
  • 82
Ponting
  • 2,248
  • 8
  • 33
  • 61

4 Answers4

5

You're almost there, just one more step: array_values($results)

André Dion
  • 21,269
  • 7
  • 56
  • 60
0

Simply get the values of the result:

$results= array_values(array_diff($b,$a));
Maxim Kumpan
  • 2,545
  • 2
  • 19
  • 23
0

To a double-sided array_diff use

$result = array_values(array_merge(array_diff($b, $a), array_diff($a, $b)));

if not use

$result = array_values(array_diff($b, $a));
Tobias Golbs
  • 4,586
  • 3
  • 28
  • 49
0

You can use array_values:

$results = array_values(array_diff($b,$a))

In PHP, all arrays are associative. array_values essentially "resets" the indexes to a numeric version.

jh314
  • 27,144
  • 16
  • 62
  • 82