The method by which PHP generates a classification tree array from a categorical list, an array of categorical lists
The example in this paper describes how PHP produces a classification tree array through a categorical list. Share to everyone for your reference. The specific analysis is as follows:
Here $list is the category list array, the key is the category ID, the value is the Category node object, the PID is the parent category ID
The PHP code is as follows:
$tree = Array (), foreach ($list as $id = = $row) {$pid = $row->pid; if ($pid = = 0) { $tree [] = & $list [$id];} else if (isset ($list [$pid])) { $parent = & $list [$pid]; $parent->children[] = & $list [$id]; Add children attribute to identify sub-category list}}
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/987249.html www.bkjia.com true http://www.bkjia.com/PHPjc/987249.html techarticle php method of generating a classification tree array by a categorical list, an array of categorical arrays This article describes the way in which PHP produces a classification tree array through a categorical list. Share to everyone for your reference. ...