Skip to content
Advertisement

How to implode subarrays in a 2-dimensional array?

I want to implode values in to a comma-separated string if they are an array:

I have the following array:

JavaScript

To achieve this I have the following code:

JavaScript

The above will also change the original array. Is there a more elegant way to create a new array that does the same as the above?

I mean, implode values if they are an array in a single line of code? perhaps array_map()? …but then I would have to create another function.

Advertisement

Answer

Just create a new array and set the elements (-;

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