中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

PHP無限極分類相關(guān)代碼

2018-07-20    來源:open-open

容器云強(qiáng)勢(shì)上線!快速搭建集群,上萬Linux鏡像隨意使用
 
//非遞歸獲取所有后代分類
function get_offspring($pids, $list)
{
    $npid = array();
    $offspring = array();
    $has_child = true;
    while($has_child)
    {
        $has_child = false;
        foreach($list as $lk => $lv)
        {
            if(in_array($lv['pid'], $pids))
            {
                $offspring[] = $lv;
                $npid[] = $lv['cid'];
                unset($list[$lk]);
                $has_child = true;
            }
        }
        $pids = $npid;
    }
    return $offspring;
}
//利用路徑字段獲取后輩分類
function get_offspring($pid)
{
    $offspring = array();
    $cats = $this->getList('cat_id,cat_name,parent_id,cat_path', array(), 0, -1);
    foreach($cats as $cv)
    {
        if(in_array($pid, explode(',', $cv['cat_path'])))
        {
            $offspring[] = $cv;
        }
    }
    return $offspring;
}
//更新后輩分類路徑
function update_offspring_path($pid, $ppath)
{
    if($ppath == ',')
    {
        $ppath = '';
    }
    $offspring = $this->get_offspring($pid);
  
    foreach($offspring as $ov)
    {
        $ov['cat_path'] = substr($ov['cat_path'], 0, strlen($ov['cat_path'])-1);
        $old_path = explode(',', $ov['cat_path']);
        foreach($old_path as $oldk => $oldv)
        {
            if($oldv == $pid)
            {
                break;
            }
            unset($old_path[$oldk]);
        }
        $new_path = $ppath.implode(',', $old_path).',';
        if(!$this->update(array('cat_path'=>$new_path), array('cat_id'=>$ov['cat_id'])))
        {
            return false;
        }
    }
    return true;
}
//將列表整理為樹形
function get_tree_list($pid, $arr, &$r)
{
    foreach($arr as $k => $v)
    {
        if($v['parent_id'] == $pid)
        {
            if(isset($r[$pid]))//設(shè)置含有子類標(biāo)記
            {
                $r[$pid]['has_child'] = 1;
            }
  
            $v['cat_path'] = trim($v['cat_path']);//計(jì)算深度
            $path_str = substr($v['cat_path'], 0, strlen($v['cat_path'])-1);
            if($path_str == '')
            {
                $v['deep'] = 0;
            }
            else
            {
                $v['deep'] = count(explode(',', $path_str));
            }
  
            $v['format'] = str_repeat(' ', 6*$v['deep']);//計(jì)算縮進(jìn)
  
            $r[$v['cat_id']] = $v;//加入有序列表
  
            unset($arr[$k]);//已加入 從無序列表中剔除
  
            $this->get_tree_list($v['cat_id'], $arr, $r);
        }
    }
}
 

標(biāo)簽:

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇: Java加密算法Triple DES

下一篇:PHP敏感詞過濾