一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

PHP無限分類的類

復(fù)制代碼 代碼如下:
<?php
/**
 * @author        YangHuan
 * @datetime    
 * @version        1.0.0
 */

/**
 * Short description.
 *
 * Detail description
 * @author       
 * @version      1.0
 * @copyright    
 * @access       public
 */
class Tree
{
    /**
     * Description
     * @var       
     * @since     1.0
     * @access    private
     */
    var $data    = array();

    /**
     * Description
     * @var       
     * @since     1.0
     * @access    private
     */
    var $child    = array(-1=>array());

    /**
     * Description
     * @var       
     * @since     1.0
     * @access    private
     */
    var $layer    = array(-1=>-1);

    /**
     * Description
     * @var       
     * @since     1.0
     * @access    private
     */
    var $parent    = array();

    /**
     * Short description. 
     *
     * Detail description
     * @param      none
     * @global     none
     * @since      1.0
     * @access     private
     * @return     void
     * @update     date time
    */
    function Tree ($value)
    {
        $this->setNode(0, -1, $value);
    } // end func

    /**
     * Short description. 
     *
     * Detail description
     * @param      none
     * @global     none
     * @since      1.0
     * @access     private
     * @return     void
     * @update     date time
    */
    function setNode ($id, $parent, $value)
    {
        $parent = $parent?$parent:0;

        $this->data[$id]            = $value;
        $this->child[$id]            = array();
        $this->child[$parent][]        = $id;
        $this->parent[$id]            = $parent;

        if (!isset($this->layer[$parent]))
        {
            $this->layer[$id] = 0;
        }
        else
        {
            $this->layer[$id] = $this->layer[$parent] + 1;
        }
    } // end func

    /**
     * Short description. 
     *
     * Detail description
     * @param      none
     * @global     none 
     * @since      1.0
     * @access     private
     * @return     void
     * @update     date time
    */
    function getList (&$tree, $root= 0)
    {
        foreach ($this->child[$root] as $key=>$id)
        {
            $tree[] = $id;

            if ($this->child[$id]) $this->getList($tree, $id);
        }
    } // end func

    /**
     * Short description. 
     *
     * Detail description
     * @param      none
     * @global     none
     * @since      1.0
     * @access     private
     * @return     void
     * @update     date time
    */
    function getValue ($id)
    {
        return $this->data[$id];
    } // end func

    /**
     * Short description. 
     *
     * Detail description
     * @param      none
     * @global     none
     * @since      1.0
     * @access     private
     * @return     void
     * @update     date time
    */
    function getLayer ($id, $space = false)
    {
        return $space?str_repeat($space, $this->layer[$id]):$this->layer[$id];
    } // end func

    /**
     * Short description. 
     *
     * Detail description
     * @param      none
     * @global     none
     * @since      1.0
     * @access     private
     * @return     void
     * @update     date time
    */
    function getParent ($id)
    {
        return $this->parent[$id];
    } // end func

    /**
     * Short description. 
     *
     * Detail description
     * @param      none
     * @global     none
     * @since      1.0
     * @access     private
     * @return     void
     * @update     date time
    */
    function getParents ($id)
    {
        while ($this->parent[$id] != -1)
        {
            $id = $parent[$this->layer[$id]] = $this->parent[$id];
        }

        ksort($parent);
        reset($parent);

        return $parent;
    } // end func

    /**
     * Short description. 
     *
     * Detail description
     * @param      none
     * @global     none
     * @since      1.0
     * @access     private
     * @return     void
     * @update     date time
    */
    function getChild ($id)
    {
        return $this->child[$id];
    } // end func

    
    /**
     * Short description. 
     *
     * Detail description
     * @param      none
     * @global     none
     * @since      1.0
     * @access     private
     * @return     void
     * @update     date time
    */
    function getChilds ($id = 0)
    {
        $child = array($id);
        $this->getList($child, $id);

        return $child;
    } // end func
} // end class

?>

使用方法

php代碼:

復(fù)制代碼 代碼如下:
<?php
//new Tree(根目錄的名字);
//根目錄的ID自動(dòng)分配為0
$Tree = new Tree('根目錄');

//setNode(目錄ID,上級(jí)ID,目錄名字);
$Tree->setNode(1, 0, '目錄1');
$Tree->setNode(2, 0, '目錄2');
$Tree->setNode(3, 0, '目錄3');
$Tree->setNode(4, 3, '目錄3.1');
$Tree->setNode(5, 3, '目錄3.2');
$Tree->setNode(6, 3, '目錄3.3');
$Tree->setNode(7, 2, '目錄2.1');
$Tree->setNode(8, 2, '目錄2.2');
$Tree->setNode(9, 2, '目錄2.3');
$Tree->setNode(10, 6, '目錄3.3.1');
$Tree->setNode(11, 6, '目錄3.3.2');
$Tree->setNode(12, 6, '目錄3.3.3');

//getChilds(指定目錄ID);
//取得指定目錄下級(jí)目錄.如果沒有指定目錄就由根目錄開始
$category = $Tree->getChilds();

//遍歷輸出
foreach ($category as $key=>$id)
{
    echo $Tree->getLayer($id, '|-').$Tree->getValue($id)."<br>/n";
}

php無限分類-php100代碼

復(fù)制代碼 代碼如下:
<?php
//無限分類,從子類找所有父類
//$id 子類ID
 function php100_xd($id){
   $sql="select * from fl where id='$id'";
   $q=mysql_query($sql);
   $rs=mysql_fetch_array($q);
   $rs['fid']==0 ? "" : fl($rs['fid']);
   echo $rs['name']."-";
   }

//讀取所有父類下面的子類
//$f頂級(jí)分類從什么開始,$s樣式
 function php100_dx($f=0,$s=""){
   $sql="select * from fl where fid=$f";
   $q=mysql_query($sql);
   $s=$s."-";
   while($rs=mysql_fetch_array($q)){
     echo "<br>$s".$rs['name'];
  flt($rs['id'],$s);
     }
   }

php技術(shù)PHP無限分類的類,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 亚洲欧美国产18 | 美女网站一区二区三区 | 在线观看91精品国产不卡免费 | 91碰视频| 天天在线影院天天在线视频 | 久久亚洲国产 | 麻豆视频国产 | 福利一区二区视频 | 男人的天堂久久精品激情a 男人进去女人爽免费视频国产 | 亚洲精品天堂在线观看 | 成人国产精品视频频 | 九色综合九色综合色鬼 | 色噜噜狠狠狠综合曰曰曰88av | www爱射网站avcom | ye321夜色资源网站 | 久久99精品久久久久久久不卡 | 草草线在成年免费视频网站 | 亚洲a人| 欧美视频www | 久久免费特黄毛片 | 色播在线永久免费视频 | 91精品综合国产在线观看 | 在线亚洲一区二区 | 米奇777四色精品人人爽 | 91福利国产在线观看 | 国产美女视频网站 | 麻豆一区二区三区四区 | 色视频在线免费看 | 2020天堂中文字幕一区在线观 | 午夜毛片免费观看视频 | 成人激情四射 | 日本不卡一区二区三区视频 | 起碰成人免费公开网视频 | 国产成人乱码一区二区三区在线 | 免费国产人做人视频在线观看 | 高清一区二区三区免费 | 韩国亚洲伊人久久综合影院 | 色噜噜狠狠先锋影音久久 | 成人va视频 | 国产欧美日韩综合精品无毒 | 欧美黑人两根巨大挤入 |