我在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 () ) ) )
我想从最深的Object处理这个变量。在外面。像这样:
有没有人有这个好的解决方案?我可以为此编写合适的算法。我只是想知道是否有人有一个经过验证的解决方案。
答案 0 :(得分:0)
无论什么解决方案,您可能需要迭代到数组中以找到最深的“名称”,然后迭代回来。您可以通过存储第一次迭代来最小化开销,并在找到最深的时自动将其反转。
抱歉午餐即将来临,所以没时间提供一个有效的例子;)