PHP无限分类的类_php技巧_脚本之家

作者: 时时彩平台-编程  发布:2020-01-12

复制代码 代码如下:

/** * 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; /** * Description * @var * @since 1.0 * @access private */ var $layer = array; /** * 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 { $this->setNode; } // end func

/** * Short description. * * Detail description * @param none * @global none * @since 1.0 * @access private * @return void * @update date time */ function setNode { $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 { foreach ($this->child[$root] as $key=>$id) { $tree[] = $id;

if $this->getList; } } // end func

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

ksort; reset;

return $parent; } // end func /** * Short description. * * Detail description * @param none * @global none * @since 1.0 * @access private * @return void * @update date time */ function getChild { 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 { $child = array; $this->getList;

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

?> 使用方法

PHP代码:

复制代码 代码如下:

//setNode; $Tree->setNode; $Tree->setNode; $Tree->setNode; $Tree->setNode; $Tree->setNode; $Tree->setNode; $Tree->setNode; $Tree->setNode; $Tree->setNode; $Tree->setNode; $Tree->setNode; $Tree->setNode;

//getChilds; //取得指定目录下级目录.如果没有指定目录就由根目录开始 $category = $Tree->getChilds();

//遍历输出 foreach ($category as $key=>$id) { echo $Tree->getLayer.$Tree->getValue."
n"; }

PHP无限分类-PHP100代码

复制代码 代码如下:

本文由时时彩平台发布于时时彩平台-编程,转载请注明出处:PHP无限分类的类_php技巧_脚本之家

关键词:

上一篇:一个PHP操作Access类_php基础_脚本之家
下一篇:没有了