Skip to content
Advertisement

Converting string to two dimensional array in php

just would like to ask how can I convert the string into two dimensional array in php. Please refer my sample code below.

JavaScript

I want to convert above string into below array and assigned it to variable.

JavaScript

Advertisement

Answer

For a new contributor, a solution with foreach is easier to understand in my opinion. The steps are commented in the code.

JavaScript

output:

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