MCPcopy Create free account
hub / github.com/CoderOpen/waimai / getTree

Function getTree

bootstrap/function.php:216–233  ·  view source on GitHub ↗

无极限分类

($array, $pid =0, $level = 0)

Source from the content-addressed store, hash-verified

214
215//无极限分类
216function getTree($array, $pid =0, $level = 0){
217 //声明静态数组,避免递归调用时,多次声明导致数组覆盖
218 static $list = [];
219 foreach ($array as $key => $value){
220 //第一次遍历,找到父节点为根节点的节点 也就是pid=0的节点
221 if ($value['pid'] == $pid){
222 //父节点为根节点的节点,级别为0,也就是第一级
223 $value['level'] = $level;
224 //把数组放到list中
225 $list[] = $value;
226 //把这个节点从数组中移除,减少后续递归消耗
227 unset($array[$key]);
228 //开始递归,查找父ID为该节点ID的节点,级别则为原级别+1
229 getTree($array, $value['id'], $level+1);
230 }
231 }
232 return $list;
233}
234function paramQuery($query, $index = '')
235{
236 $queryParts = explode('&', $query);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected