Reorganizace kodu pro generovani statistik
[mirrors/SokoMan.git] / assistants / category-tree.inc.php
CommitLineData
661e2988
TM
1<pre><?php
2$result = $this->db->safe_query_fetch('SELECT * FROM category');
3
4function addleaf(&$tree, $levels, $category='') {
5 if(!count($levels)) return;
6 $current = array_shift($levels);
7 $category .= '/'.$current;
8 if(!isset($tree[$current])) $tree[$current] = array();
9 $tree[$current]['__PATH__'] = $category;
10 addleaf($tree[$current], $levels, $category);
11}
12
13$tree = array();
14foreach($result as $row) {
15 $row_parts = preg_split('/\//', $row['category_name']);
16 addleaf($tree, $row_parts);
17}
18
19print_r($tree);
This page took 0.122841 seconds and 4 git commands to generate.