Computer Office ( computer machine ( notebook , Tablet PC , super-pole ), Peripheral Products )
Data format:
Array (' cat_id ' + ', ' cat_name ' = ' computer Office ', ' parent_id ' = ' 0 ', ' children '
Array (
Array (' cat_id ' = ' 8 ', ' cat_name ' = ' computer machine ', ' parent_id ' + ', ' children ' =
Array (
Array (' cat_id ' = ' + ', ' cat_name ' = ' tablet ', ' parent_id ' = ' 8 ', ' Children ' =>array ())
Array (' cat_id ' = ' + ', ' cat_name ' = ' notebook ', ' parent_id ' = ' 8 ', ' Children ' =>array ())
Array (' cat_id ' = ' + ', ' cat_name ' + ' super-Ben ', ' parent_id ' = ' 8 ', ' Children ' =>array ())
)
Array (' cat_id ' = ' one ', ' cat_name ' + ' peripheral products ', ' parent_id ' + ', ' Children ' =>array ())
)
)
<?php
Public Function getnextedlist ($p _id=0) {
Get all the listings
$list = $this->getlist ();
Make nested data, recursively find
return $this->getnexted ($list, $p _id);
}
Public Function getnexted ($list, $p _id) {
$children =array ();
foreach ($list as $row) {
if ($row [' parent_id ']== $p _id) {
$row [' Children ']= $this->getnexted ($list, $row [' cat_id ']);
$children []= $row;
}
}
return $children;
}
?>
Tree-like classification algorithm (recursive)