My problem.. I have a PHP array that looks like this:
[1013] => [1154]
[1013] => [1322]
[1154] => [1525]
[1525] => [1526]
How can I take that and move it to something like this:
[1013] => [1154] => [1525] => [1526]
[1013] => [1322]
So it sort of makes a tree that associates to the top level array item. I do not have control over how the data comes to me, it’s generated through a third-party API and given to me just like that.
Logic: Client 1013 is the main account. Client 1154 is a client of 1013. Client 1322 is a client of 1013. Client 1525 is a client of 1154. I want to get it to a multi-dimension array so I can show this in a tree format.
Here you go!:
This outputs:
The idea is to see which nodes have no children. Then, iterate through their parents. You probably don’t need the output like it is right now, but I’m sure you can work it out this way. Enjoy!