$value)
{
if($value['parent_cid' ] == $parent_id)
{
//$value[ 'level'] = $level;
$arrTree[] = $value['cid'];
unset($arrCat[$key]); //注销当前节点数据,减少已无用的遍历
self::getMenuTree($arrCat,$value[ 'cid'],$level);
}
}
return $arrTree;
}
用上面这个方法的前提是要把分类写到缓存文件中,缓存文件写入方法如下:
db;
$listinfo = $db->createCommand("select name,cid,parent_cid,root_cid from item_cat_info")->queryAll();
foreach($listinfo as $val)
{
$arr[$val['cid']] = array('cid'=>$val['cid'],'name'=>$val['name'],'parent_cid'=>$val['parent_cid'],'root_cid'=>$val['root_cid']);
}
原文链接:https://www.f2er.com/php/24401.html$applist = "<?php\nreturn ".var_export($arr,true).";\n?>";
file_put_contents($filepath.'itemcat.PHP',$applist);
}