/** * Check recursively to find the number of children in $e with tag $child_tag * return number of qualified children */ public static function count_children_by_tag($e, $tag) { $num = 0; foreach ($e->children() as $child) { if ($child->tag == $tag) { $num++; } else { $num += BasicChecks::count_children_by_tag($child, $tag); } } return $num; }