グループの配列をループしています。各要素には親 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
配列の 5 番目のレベルに複数の親を持つ複数のグループがある場合でも、これを解決して特別な関数を呼び出すにはどうすればよいですか?
私の質問を十分に明確に定式化したことを願っています。