网上找来的一个递归类,自己做了一些代码的调整。
调用:
makeTree($list,['type'=>$tree,'primary_key'=>'d_id','parent_key'=>'d_pid'])
list为原始数据,[ ]内的是$config参数
class Tree
{
protected static $config = array(
/* 主键 */
'primary_key' => 'id',
/* 父键 */
'parent_key' => 'pid',
/* 展开属性 */
'expanded_key' => 'expanded',
/* 叶子节点属性 */
'leaf_key' => 'leaf',
/* 孩子节点属性 */
'children_key' => 'children',
/* 是否展开子节点 */
'expanded' => true,
/* 生成方式 line线性 tree树结构 */
'tree_type' => 'line'
);
/* 结果集 */
protected static $result = array();
/* 层次暂存 */
protected static $level = array();