码迷,mamicode.com
首页 > 编程语言 > 详细

数组树函数

时间:2015-03-20 16:07:28      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:

function getTree($data, $pid = 0, $key = ‘id‘, $pKey = ‘pid‘, $childKey = ‘child‘, $maxDepth = 0){
	static $depth = 0;
	$depth++;
	if (intval($maxDepth) <= 0)
	{
		$maxDepth = count($data) * count($data);
	}
	if ($depth > $maxDepth)
	{
		exit("error recursion:max recursion depth {$maxDepth}");
	}
	$tree = array();
	foreach ($data as $rk => $rv)
	{
		if ($rv[$pKey] == $pid)
		{
			$rv[$childKey] = getTree($data, $rv[$key], $key, $pKey, $childKey, $maxDepth);
			$tree[] = $rv;
		}
	}
	return $tree;
}

 

数组树函数

标签:

原文地址:http://www.cnblogs.com/dsczs/p/4353739.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!