Êý×飺
$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/»Æɽ/»Æɽһ½Ç"£¬ÇëÎÊÓÐʲôºÃµÄ°ì·¨£¿×¢£ºÊý×é¿ÉÄÜÊÇÎÞÏÞ²ã´ÎµÄ¡£

解决方案 »

  1.   

    乱码?为什么不能修改自己发的帖子? 太不人性化了吧数组:
    $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/黄山/黄山一角",请问有什么好的办法?注:数组可能是无限层次的。
      

  2.   

    无限数型结构 不建议用这种数据结构表示 给你一个数型类: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 = 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
      

  3.   

    或者你可以采用OO方法分解问题来设计会比较简单 比如:class Tree
    {
      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";
    }*/
      

  4.   

    程序员,还想没日没夜的干下去吗??最新项目:懂网络,零投入,不耽误正常工作,业余时间让你月赚2000!!!!!! 财富网址:www.dmdigo.cn
      

  5.   

    2楼的值得考虑一般标识一人路径可以这么标识本身id ,父节点id,本节点值(这里可指目录)递归生成树结构就可以了
      

  6.   

    不明白为什么要把xml文挡弄成这样后再处理