troubleshooting Question

PHP associative array to tree array

Avatar of Edu de la T
Edu de la T asked on
PHP
10 Comments1 Solution244 ViewsLast Modified:
I want translate an array on 'n' lenght, and 'n' elements like this:

$array = array(
                0 => array(1314,1317,1320),
                1 => array(1314,1317,1321),
                2 => array(1314,1318,1320),
                3 => array(1314,1318,1321),
                4 => array(1314,1319,1320),
                5 => array(1314,1319,1321),
                6 => array(1315,1318,1321),
                7 => array(1315,1319,1321),
                8 => array(1315,1319,1322)
                );

to a tree array like this:

$output = array(
                1314 => array(
                            1317 => array(
                                        1320 => array(),
                                        1321 => array()
                                        ),
                            1318 => array(
                                        1320 => array(),
                                        1321 => array()
                                        ),
                            1319 => array(
                                        1320 => array(),
                                        1321 => array()
                                        )
                            ),
                1315 => array(
                            1318 => array(
                                        1321 => array()
                                        ),
                            1319 => array(
                                        1321 => array(),
                                        1322 => array()
                                        )
                            )
                );

I have been triying hard for days, but i didn't get it.
Please, any help?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 10 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros