Skip to content
Advertisement

Merging 3 arrays in PHP

I have 3 arrays as below.

JavaScript

I want to merge these 3 arrays as below $result_array. I have written a code as below. But It gave a empty array.

JavaScript

Code:

JavaScript

Please help me to do this.

Advertisement

Answer

Simply foreach over the first array and use the index as the key to the other arrays.

JavaScript

Remember this will only work if all 3 arrays are the same length, you might like to check that first

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