Skip to content
Advertisement

Merge two arrays with same length but different keys?

I have an array like:

JavaScript

And another array like:

JavaScript

How do I merge them both into 1 array where the result looks like:

JavaScript

They will always be the same length but never have the same keys. I already tried array_merge and also $result = $array1 + $array2; but that did not produce the desired result. There must be an easy way for this?

Advertisement

Answer

You can do it this way:

Initial data

JavaScript

Result

JavaScript

Output

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