-4

I have two associative array which I want to merge based on the index / key of an array, i don't want it to overwrite any of the array values from the index.

Array 1:
Array
(
    [66529] => Array
        (
            [Download] => ON
        )
    [66587] => Array
        (
           [Download] => ON
        )
)

Array 2:
Array
(
    [66587] => Array
        (
            [PPT] => ON
        )
    [66529] => Array
        (
            [PPT] => OFF
        )
)

Merged Array should be:

Array
(
    [66529] => Array
        (
            [Download] => ON
            [PPT] => OFF
        )
    [66587] => Array
        (
           [Download] => ON
            [PPT] => ON
        )
)

I know this can be done using the loops, but I am looking for in-built php functions to do this.

DevDonkey
  • 4,835
  • 2
  • 27
  • 41
Rumi
  • 229
  • 1
  • 13

1 Answers1

1

Finally, got the expected result. Below is the solution that works for me

$result = array_replace_recursive($array1, $array2);

Rumi
  • 229
  • 1
  • 13