我正在循环一组组,每个元素都包含一个父 ID。
$currentparent = $group['grpId']; //$group is the current element in a loop wrapped around this piece of code
$currentlevel = 0;
foreach($groups as $grp)
{
$parent = $grp['grpParentId'];
if($parent != $currentparent && $currentlevel != 6)
{
//adding layer
$currentlevel++;
//changing parent
$currentparent = $grp['grpParentId'];
}
if($currentlevel == 6)
{
//call a special function
}
else
{
//call the regular function
}
}
这适用于这样的数组:
group
-group
--group
---group
----group
----- group <- the only group on the 5th layer
但不适用于在第 5 级具有多个组的数组:
group
-group
--group
--group
---group
----group
-----group <- 5th layer
----group
-----group <- 5th layer too, but diff parent
即使在数组的第五级有多个具有多个父级的组时,我如何解决此问题以调用特殊函数?
我希望我的问题足够清楚。