$member_count)) . ')'; } } /** * Recursively count group members. * * @param FarmAsset $group * The group asset to recurse into. * * @return int * Returns the number of group members in the group, and in sub-groups. */ function farm_group_members_count_recursive(FarmAsset $group) { // Start an empty counter. $count = 0; // Load the members of the group. $members = farm_group_members($group); // If there are no members, return. if (empty($members)) { return $count; } // Count the members. $count += count($members); // Iterate through the members. foreach ($members as $member) { // If the member is a group, recurse into it and count it's members. if ($member->type == 'group') { $count += farm_group_members_count_recursive($member); } } // Return the final count. return $count; }