Skip to content
Advertisement

Merge an array value with another array

I Have 2 arrays:

JavaScript

I am looking to merge both of them to get the below result using foreach:

JavaScript

So the result will be displayed like:

JavaScript

Advertisement

Answer

JavaScript

You need to keep a running integer count of the key offset to be able to get the same index from $values; we’re doing this here by looping over the keys and using their index as $i.

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