function tree_count($data, $field = false, $match = false) { // Find Occurence of match in a tree. //$unpublish_count = tree_count($dbresult, "wiki_cat_status", "0")-1; if (!isset($counter)) { $counter = 0; } else { $counter =& $counter; } foreach ($data as $arr) { if (!empty($field)) { if ($arr[$field] == "{$match}") { $counter++; } } else { $counter++; } if (array_key_exists("children", $arr)) { $counter = tree_count($arr['children'], $field, $match) + $counter; } } return $counter; }
/** * Get the occurences of a column name matching value * $unpublish_count = tree_count($dbtree_result, "wiki_cat_status", "0")-1; * @param $data - $data = dbquery_tree(...); * @param bool $field * @param bool $match * @return int */ function tree_count($data, $column_name = FALSE, $value_to_match = FALSE) { // Find Occurence of match in a tree. // if (!isset($counter)) { $counter = 0; } else { $counter =& $counter; } foreach ($data as $arr) { if (!empty($column_name)) { if ($arr[$column_name] == $value_to_match) { $counter++; } } else { $counter++; } if (array_key_exists("children", $arr)) { $counter = tree_count($arr['children'], $column_name, $value_to_match) + $counter; } } return (int) $counter; }