无限分类函数,你懂得 源数据格式:$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]);$
无限分类函数,你懂得
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; }