Skip to content
Advertisement

How can I achieve a new array with columns from another array’s rows? [php]

I have this kind of array:

JavaScript

I need to obtain this:

JavaScript

Can anyone help me please?

Advertisement

Answer

Use str_getcsv, as it CSV, then just assign the first and second columns as the array keys, normalising it and then once you have that you can loop over it and built your desired result.

So aiming to make this structure:

JavaScript

You can loop over to make:

JavaScript

Like:

JavaScript

https://3v4l.org/11VaW

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