标签:exp nbsp log 技术 foreach php htm height bsp
1、数据库设计。
2、PHP代码。
//一维数组的形式
function tree(&$list, $pid = 0, $level = 0, $html = ‘----------‘) { static $tree = array(); foreach ($list as $v) { if ($v[‘pid‘] == $pid) { $v[‘level‘] = $level; $v[‘html‘] = str_repeat($html, $level); $tree[] = $v; tree($list, $v[‘id‘], $level + 1); } } return $tree; }
//多维数组的形式
function toLayer($cate, $pid = 0){ $arr = array(); foreach ($cate as $v){ if ($v[‘pid‘] == $pid){ $v[‘child‘] = toLayer($cate, $v[‘id‘]); $arr[] = $v; } } return $arr; }
标签:exp nbsp log 技术 foreach php htm height bsp
原文地址:http://www.cnblogs.com/wwqphp/p/6524259.html