Skip to content
Advertisement

How to convert Two dimentional array into Three dimentional in PHP?

I have below two dimentional array

JavaScript

And I want to convert this array into Three dimentional according to Parent-Child value like below array.

JavaScript

In this first iterator is value of ‘category’ key which iterate two times. second iteration is for ‘attribute’ and likewise third is for ‘option’, which iterate 8 times.

Addition: What if I want to do reverse. I have second array and want to convert in first one.

Thanks.

Advertisement

Answer

JavaScript

Strings with numbers for array keys will be converted to int in PHP.

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