Skip to content
Advertisement

Replace multidimensional array values with one-dimensional array

I would like to change the values in one multidimensional array if a corresponding key is found in another flat, associative array.

I have these two arrays:

JavaScript

I want the array to look like this:

JavaScript

I get the $semi array back from my input field and want to merge it into $full to save it into my database.

I already tried array_replace() like:

JavaScript

Advertisement

Answer

You should loop your $semi array and check if it exists in one of $full arrays, then add to it:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement