Skip to content
Advertisement

How to change this array into keys and values

I have this array…

JavaScript

What’s the best way for me to change this array so I can save it like this…

JavaScript

I’ve started doing something like looping through them and this… but this gives me one array element per new array.

JavaScript

Advertisement

Answer

You can use array_column() to index the inner array, specifying the column to use as the value and the one to index it by…

JavaScript

gives…

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