php function shopActiveCategories gparent data result tree function us

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
function shopActiveCategories(){
$gparent = 0;
$data = [];
$result = [];
$tree = function() use (&$tree, &$gparent, &$data, &$result){
$tparent = $gparent;
foreach ($data as $id => $parent){
if (in_array($id, $result) != true && $parent == $tparent){
$result[$id] = $id;
$gparent = $id;
unset($data[$id]);
$tree();
}
}
return array_keys($result);
};
$query = db_query('
SELECT
{catalog_tovar}.code as id,
{catalog_tovar}.parent as parent
FROM
{catalog_tovar}
WHERE
{catalog_tovar}.level >= 0
');
while ($row = mysql_fetch_object($query)){
$data[$row->id] = $row->parent;
}
return $tree();
}
?>