I have the following Object/Array structure in PHP:
Object ( id => *random number 10000-99999* name => parent => *reference to the parent Object* // null, so this is the root element child => Array ( [0] => Object ( id => *random number 10000-99999* name => row parent => *reference to the parent Object* // points to root element child => Array ( [0] => Object ( id => *random number 10000-99999* name => column parent => *reference to the parent Object* //row child => Array ( [0] => Object ( id => *random number 10000-99999* name => link parent => *reference to the parent Object* // column child => Array () ) ) ) [1] => Object ( id => *random number 10000-99999* name => column2 parent => *reference to the parent Object* //row child => Array ( [0] => Object ( id = *random number 10000-99999* name = article parent => *reference to the parent Object* // column2 child => Array () ) ) ) [2] => Object ( id = *random number 10000-99999* name = column3 parent => *reference to the parent Object* //row child => Array () ) ) ) [1] => Object ( id = *random number 10000-99999* name = link2 parent => *reference to the parent Object* // points to root element child => Array () ) ) )
I want to process this variable from the deepest Object. In to out. Like this:
Does anyone has a good solution for this? I can write the suitable algorith for this. I just want to know does anybody has a proven solution.
Whatever solution, you probably need to iterate into the array to find the deepest "name" and then iterate back. You can minimize overhead by storing the first iteration and reverse it automatically upon finding the deepest.
Sorry lunch is looming, so no time to provide a working example ;)