- 话不多说 上代码 简单明了
php 源码:
public function getTree($list,$pid = 0)
{
$tree = array();
foreach($list as $k => $v)
{
if($v['parentid'] == $pid)
{ //父亲找到儿子
$v['children'] = $this->getTree($list, $v['id']);
$tree[] = $v;
}
}
return $tree;
}
/**
* @return 查询部门组织架构
*/
public function selectdepartemtlist(){
//实例化
$DictionaryIndex = new Department();
//转数组
$result = $DictionaryIndex->select()->toArray();
//数据传到getChild方法
$data= $this->getTree($result);
return $data;
}
数据表结构:
'id' :ID
'name':名称
'parentid' :父级ID
easy!!!!!!!!!!!!!!!!!!!!!!!

被折叠的 条评论
为什么被折叠?



