Home > php教程 > php手册 > 无限分类

无限分类

WBOY
Release: 2016-06-06 19:32:32
Original
1239 people have browsed it

无限分类函数,你懂得 源数据格式:$arr = array(array(id=1, name=分类1, parentId=0),。。。); 无 function category($data, $parentId=0){$category = array();foreach ($data as $key=$value){if ($value['parentId'] == $parentId){unset($data[$key]);$

无限分类函数,你懂得
源数据格式:$arr = array(array('id'=>1, 'name'=>'分类1', 'parentId'=>0),。。。);
function category(&$data, $parentId=0)
{
	$category = array();
	foreach ($data as $key=>$value)
	{
		if ($value['parentId'] == $parentId)
		{
			unset($data[$key]);
			$value['child'] = category($data, $value['id']);
			$category[] = $value;
		}
	}
	return $category;
}
Copy after login
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template