G
G
GrigoryMorozov2021-01-27 12:07:40
PHP
GrigoryMorozov, 2021-01-27 12:07:40

Are there ready-made solutions for smart merging of associative arrays?

There is a config like this:

{
  "name1": "...",
  "name2": "...",
  "name3": {
    "name4": "...",
    "name5": {
      "name6": "..."
    },
    "name7": "..."
  }
}

You need to merge it with this config:

{
  "name3": {
    "name5": {
      "name6": "123"
    }
  }
}

The result should be the original config with the changed value of the "name6" parameter.

Please let me know if there are solutions for this problem.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2021-01-27
@GrigoryMorozov

array_merge_recursive() will not work as expected with integer keys.
Therefore, you will have to write your own, look for a ready-made one, or even install the graze / array-merger package

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question