Êý×飺
$test = Array([0] => Array(
[@attributes] => Array
(
[catalogID] => 112
[catalogName] => music
) [catalogNode] => Array
(
[0] => Array
(
[@attributes] => Array
(
[catalogID] => 711
[catalogName] => °×ÔÆɽ
) ) [1] => Array
(
[@attributes] => Array
(
[catalogID] => 712
[catalogName] => ·ï»Ëɽ
) ) [2] => Array
(
[@attributes] => Array
(
[catalogID] => 113
[catalogName] => »Æɽ
) [catalogNode] => Array
(
[0] => Array
(
[@attributes] => Array
(
[catalogID] => 114
[catalogName] => »Æɽһ½Ç
) ) [1] => Array
(
[@attributes] => Array
(
[catalogID] => 115
[catalogName] => »Æɽһ½Ç
) ) [2] => Array
(
[@attributes] => Array
(
[catalogID] => 116
[catalogName] => »Æɽһ½Ç
) ) ) ) ) ) [1] => Array
(
[@attributes] => Array
(
[catalogID] => 13677777777113
[catalogName] => video
) ) [2] => Array
(
[@attributes] => Array
(
[catalogID] => 13677777777114
[catalogName] => doc
) ) [3] => Array
(
[@attributes] => Array
(
[catalogID] => 13677777777115
[catalogName] => misc
) ) )
ÎÒÏë»ñÈ¡[catalogID] => 116 [catalogName] => »Æɽһ½Ç Õâ¸ö½ÚµãµÄ·¾¶"/music/»Æɽ/»Æɽһ½Ç"£¬ÇëÎÊÓÐʲôºÃµÄ°ì·¨£¿×¢£ºÊý×é¿ÉÄÜÊÇÎÞÏÞ²ã´ÎµÄ¡£
$test = Array([0] => Array(
[@attributes] => Array
(
[catalogID] => 112
[catalogName] => music
) [catalogNode] => Array
(
[0] => Array
(
[@attributes] => Array
(
[catalogID] => 711
[catalogName] => °×ÔÆɽ
) ) [1] => Array
(
[@attributes] => Array
(
[catalogID] => 712
[catalogName] => ·ï»Ëɽ
) ) [2] => Array
(
[@attributes] => Array
(
[catalogID] => 113
[catalogName] => »Æɽ
) [catalogNode] => Array
(
[0] => Array
(
[@attributes] => Array
(
[catalogID] => 114
[catalogName] => »Æɽһ½Ç
) ) [1] => Array
(
[@attributes] => Array
(
[catalogID] => 115
[catalogName] => »Æɽһ½Ç
) ) [2] => Array
(
[@attributes] => Array
(
[catalogID] => 116
[catalogName] => »Æɽһ½Ç
) ) ) ) ) ) [1] => Array
(
[@attributes] => Array
(
[catalogID] => 13677777777113
[catalogName] => video
) ) [2] => Array
(
[@attributes] => Array
(
[catalogID] => 13677777777114
[catalogName] => doc
) ) [3] => Array
(
[@attributes] => Array
(
[catalogID] => 13677777777115
[catalogName] => misc
) ) )
ÎÒÏë»ñÈ¡[catalogID] => 116 [catalogName] => »Æɽһ½Ç Õâ¸ö½ÚµãµÄ·¾¶"/music/»Æɽ/»Æɽһ½Ç"£¬ÇëÎÊÓÐʲôºÃµÄ°ì·¨£¿×¢£ºÊý×é¿ÉÄÜÊÇÎÞÏÞ²ã´ÎµÄ¡£
解决方案 »
- 做什么样的网站好勒?关键是可以偷懒的网站
- phpmyadmin中查看中文字符乱码问题。
- php文件解析
- php 由表单select option传递过来的值,mysql select不能作为调用数据的条件?
- sql语句的疑问???????
- PHP操作ORACLE数据库如何添加自动编号的数据?
- 请问哪里有关于新闻组和邮件列表的文章?老师让写两篇关于他俩的文章啊。另外,请问有朋友用PHP作出支持他们的程序吗?(不知这样问对不
- php能够读取flash文件的长和宽吗?
- 在php中如何取得用户上网的计算机的操作系统名称,
- 关于图片引用URLREWRITE的问题。
- 求这个条件的正测表达式
- smarty的问题,输出运算结果
$test = Array([0] => Array(
[@attributes] => Array
(
[catalogID] => 112
[catalogName] => music
) [catalogNode] => Array
(
[0] => Array
(
[@attributes] => Array
(
[catalogID] => 711
[catalogName] => 白云山
) ) [1] => Array
(
[@attributes] => Array
(
[catalogID] => 712
[catalogName] => 凤凰山
) ) [2] => Array
(
[@attributes] => Array
(
[catalogID] => 113
[catalogName] => 黄山
) [catalogNode] => Array
(
[0] => Array
(
[@attributes] => Array
(
[catalogID] => 114
[catalogName] => 黄山一角
) ) [1] => Array
(
[@attributes] => Array
(
[catalogID] => 115
[catalogName] => 黄山一角
) ) [2] => Array
(
[@attributes] => Array
(
[catalogID] => 116
[catalogName] => 黄山一角
) ) ) ) ) ) [1] => Array
(
[@attributes] => Array
(
[catalogID] => 13677777777113
[catalogName] => video
) ) [2] => Array
(
[@attributes] => Array
(
[catalogID] => 13677777777114
[catalogName] => doc
) ) [3] => Array
(
[@attributes] => Array
(
[catalogID] => 13677777777115
[catalogName] => misc
) ) )
我想获取[catalogID] => 116 [catalogName] => 黄山一角 这个节点的路径"/music/黄山/黄山一角",请问有什么好的办法?注:数组可能是无限层次的。
{
/**
* 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 = null)
{
$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 getLevel ($id)
{
return $this->layer[$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 isset($this->parent[$id]) ? $this->parent[$id] : array();
} // 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 isset($this->child[$id]) ? $this->child[$id] : array();
} // 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
{
private $nodes = array(); // 储存节点结构
...
public function getNode(){...}
public function setNode(){...}
...
}class Node
{
private $parent; // 父节点
private $nodeinfo = array(); // 本节点信息
public function getParent(){...}
public function setParent(){...}
}补上上面 Tree Class 的使用实例:$Tree->setNode(1, 0, '目录1');
$Tree->setNode(2, 1, '目录2');
$Tree->setNode(5, 3, '目录5');
$Tree->setNode(3, 0, '目录3');
$Tree->setNode(4, 2, '目录4');
$Tree->setNode(9, 4, '目录9');
$Tree->setNode(6, 2, '目录6');
$Tree->setNode(7, 2, '目录7');
$Tree->setNode(8, 3, '目录8');$category = $Tree->getChilds();//遍历输出
foreach ($category as $key=>$id)
{
echo $id.$Tree->getLayer($id, '|-').$Tree->getValue($id)."\n";
}*/