thinkphp傳參 {:U(GROUP_NAME . '/Category/addcate',array('pid' => $v['ID']))} //不能使用.語法
$pid = isset( $_GET['pid']) ?$_GET['pid']:0; 等於I方法 I('pid',0,'intval');
//遞歸
寫成一個類,類寫在 Class類中
category.class.php
引用類,import('class.category',APP_PATH);
調用類,category::unlimitedForLevel()
組合一維數組
class category{
//數據,標識符,PID,等級
Static Public function unlimitedForLevel($cate,$html = '--',$pid=0,$level=0){
$array = array();//定義一個空數組
foreach($cate as $v){
if($v['pid'] == $pid){
$v['level'] = $level +1; //等級加1
$v['html'] = str_repeat($html,$level); //根據等級複製標識符
$arr[] = $v;
$arr = array_merge($arr,sele::unlimitedForLevel($cate,$html,$v['id'],$level+1));//合併
}
return $arr;
}
}
}