How can I create a multi- dimensional array from a string?
-
I have this string. $str = "a b c d"; I'd like to make a multi-dimensional array from it like this. $array = array("a" => array("b" => array("c" => array("d" => array())))); print_r($array); This page http://stackoverflow.com/questions/4920515/how-can-i-create-multidimensional-arrays-from-a-string-in-php/4920691#4920691 suggests a solution for a different string format so I cannot wrap my head around.
-
Answer:
Okay, got it working. $str = "a b c d"; foreach (array_reverse(explode(" " , $str)) as $key => $value) $marr = array($value => isset($marr) ? $marr : array()); print_r($marr);
Anonymous at Quora Visit the source
Related Q & A:
- How can i create a mobile application server?Best solution by Stack Overflow
- How can i create a new blog?Best solution by Yahoo! Answers
- How can I create a new font?Best solution by Yahoo! Answers
- How can I create a cute, artsy, unique facebook profile?Best solution by Quora
- How can I create a yahoo group?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.