Skip to content
Advertisement

Merge every 2 arrays in a Multidimensional array PHP

So, this is a complicated question for me. Let’s say we have an array that goes like this:

JavaScript

supposed to be FAQs question and answer are more than 1, the arrays above separates the faq question and faq answer in 2 different arrays and given that the array is a result of a 3rd party API (which you cannot control), how can I merge every 2 arrays so that faq answer and question will be in 1 array?

Sorry for this question, I am really trying to understand this problem but no luck. I appreciate any answers.

Advertisement

Answer

Just loop through your values and add them to a new array.

Something like this

JavaScript

For the example you gave, this would be the output of the above loop.

JavaScript

Here is something closer to the format you mentioned in your comment.

JavaScript

Output is something like this

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