1

I have two associative arrays as following

    Array
(

    [0] => Array
        (
            [description] => aaaaaa
            [value] => 11111
            [id] => 14
        )

    [1] => Array
        (
            [description] => dddddd
            [value] => 44444
            [id] => 0
        )

)




Array
(

    [0] => Array
        (
            [id] => 14
            [value] => 11111
            [description] => aaaaaa
        )

    [1] => Array
        (
            [id] => 15
            [value] => 222222
            [description] => bbbbbb
        )

    [2] => Array
        (
            [id] => 16
            [value] => 333333
            [description] => cccccc
        )

)

The result I am getting is

Array
(

    [0] => Array
        (
            [description] => aaaaaa
            [value] => 11111
            [id] => 14
        )

    [1] => Array
        (
            [description] => dddddd
            [value] => 44444
            [id] => 0
        )

)

Noting that dddd is available in the first array but not the second.

I am using the array_intersect_assoc( $array1, $array2 ) function. Please help. It's not logical at all to return such results

Ram Sharma
  • 8,676
  • 7
  • 43
  • 56
  • It is clear what you want achieve here, this fucntion "array_intersect_assoc" calculates the intersection of associative arrays with additional index check. Further more what i see there is multidimensional array, just note – Mubo Oct 10 '14 at 10:45
  • @mubo he need to get the duplicate record from two arrays – sasi kanth Oct 10 '14 at 10:49
  • @sasikanth exactly ! and only the duplicate, maybe it's loosing it since it's a multidimensional arrays comparison –  Oct 10 '14 at 10:53

2 Answers2

0

Use below code

$intersect = array_uintersect($arr1, $arr2, 'compareDeepValue');
 print_r($intersect);

 function compareDeepValue($val1, $val2)
 {
  return strcmp($val1['value'], $val2['value']);
 }
sasi kanth
  • 2,637
  • 4
  • 17
  • 29
0

If you will enable php notices you will see next

Notice: Array to string conversion

You can get exhaustive answer about your problem here

Good luck!

Community
  • 1
  • 1
MustDie1Bit
  • 560
  • 4
  • 16