I have a function that retrieve the details of family member and can count the total of family member to the fifth generation. Below is my code snipped
function familyTree($id)
{
$total = 0;
foreach(family($id) as $child){
$total++;
foreach(family($child->id) as $grand_child){
$total++;
foreach(family($grand_child->id) as $great_grand_child){
$total++;
foreach(family($great_grand_child->id) as $great_great_grand_child){
$total++;
}
}
}
}
return $total;
}
My challenge is, how do I calculate the total number of family under the parent or anyone to infinity generation?
>Solution :
From the above comment by Giso Stallenberg, the correct answer should be the one below:
function familyTree($id)
{
$family = family($id);
$total = count($family);
foreach(family($id) as $child){
$total += familyTree($child->id);
}
return $total;
}