acc->getAccountCategories($acgroup_id); $array = json_decode(json_encode($AccountCategories), true); $tree = buildCategoryTree($array, false); function buildCategoryTree($categories, $parent_id = 0, $showZero = true) { $tree = array(); foreach ($categories as $category) { if ($category['parent_category_id'] == $parent_id) { $children = buildCategoryTree($categories, $category['accategory_id'], $showZero); if (!empty($children)) { $category['children'] = $children; } if ($showZero && ($category['dr'] !== 0 || $category['cr'] !== 0)) { $tree[] = $category; } elseif (!$showZero && ($category['dr'] !== 0 && $category['cr'] !== 0)) { $tree[] = $category; } } } return $tree; } function displayCategoryTree($tree) { echo '
' . $category['accategory_id'] . ' | '; echo ''. ($category['parent_category_id'] == 0 ? "" : "") .'' . $category['accategory_name'] . '' .( $category['parent_category_id'] == 0? "" : "") . ' | '; echo '' . myCurrency($category['dr']) . ' | '; echo '' . myCurrency($category['cr']) . ' | '; echo '
'; displayCategoryTree($category['children']); echo ' | '; echo '