Загадки рекурсии

Oleg061

Новичок
Доброго времени суток, уважаемые гуру, очень прошу помощи
Есть мой проект, в котором есть класс (реализация хтмл-списков), в котором есть практически основной метод, который рекурсивно обходит многомерные массивы, изготовляя одномерный со всей нужной инфой...
Всё бы было хорошо, если бы порой(по до сих пор не известным мне причинам) он не занимался самодеятельностью...

Это, собственно, сам метод...
PHP:
protected static $list;     protected static $dim=1;       protected static $i=0;

protected function list_from_arr($arr)
        {
            $veiw="list";
            
            foreach($arr as $key=>$val)
            {
                if (is_array($val))
                {
                    $content=array("value"=>"$key","description"=>"");
                    self::$list[self::$i++]=new subelements($veiw,"dir",self::$dim++,$content);//Операция ++ идет после выполнения действия и служит только для уменьшения кода
                    self::$list[self::$i]=$this->list_from_arr($val);
                }
                else
                {
                    $content=array("value"=>"$val","description"=>"$key");
                    self::$list[self::$i++]=new subelements($veiw,"word",self::$dim,$content);
                    continue;
                }
                self::$dim--;                            
            }
            
            $list_value=self::$list;     
            return $list_value;
        }
Это класс, массив из экземпляров которого я создаю:
PHP:
class subelements
    {
        public $veiw;
        public $position;
        public $dim;
        public $content=array("value","description","result");
        
        public function __construct($veiw,
                                    $position="dir",
                                    $dim=0,
                                    $content=array("description"=>"","result"=>""))
        {
            $this->veiw=$veiw;
            $this->position=$position;
            $this->dim=$dim;
            $this->content=$content;
        }     
    }
И тестовый пример с результатом работы метода (результат работы var_dump()):
PHP:
["Земляные работы"]=>
  array(4) {
    [1]=>
    string(1) "1"
    [2]=>
    string(1) "2"
    [3]=>
    string(1) "3"
    [4]=>
    string(1) "4"
  }
  ["Бетонные работы"]=>
  array(4) {
    [5]=>
    string(1) "5"
    [6]=>
    string(1) "6"
    [7]=>
    string(1) "7"
    [8]=>
    string(1) "8"
  }
  
На выходе -
array(,,,) { - эта часть правильна
  [0]=>
  object(subelements)#7 (4) {
    ["veiw"]=>
    string(4) "list"
    ["position"]=>
    string(3) "dir"
    ["dim"]=>
    int(1)
    ["content"]=>
    array(2) {
      ["value"]=>
      string(15) "Земляные работы"
      ["description"]=>
      string(0) ""
    }
  }
  [1]=>
  object(subelements)#8 (4) {
    ["veiw"]=>
    string(4) "list"
    ["position"]=>
    string(4) "word"
    ["dim"]=>
    int(2)
    ["content"]=>
    array(2) {
      ["value"]=>
      string(1) "1"
      ["description"]=>
      string(1) "1"
    }
  }
  [2]=>
  object(subelements)#9 (4) {
    ["veiw"]=>
    string(4) "list"
    ["position"]=>
    string(4) "word"
    ["dim"]=>
    int(2)
    ["content"]=>
    array(2) {
      ["value"]=>
      string(1) "2"
      ["description"]=>
      string(1) "2"
    }
  }
  [3]=>
  object(subelements)#10 (4) {
    ["veiw"]=>
    string(4) "list"
    ["position"]=>
    string(4) "word"
    ["dim"]=>
    int(2)
    ["content"]=>
    array(2) {
      ["value"]=>
      string(1) "3"
      ["description"]=>
      string(1) "3"
    }
  }
  [4]=>
  object(subelements)#11 (4) {
    ["veiw"]=>
    string(4) "list"
    ["position"]=>
    string(4) "word"
    ["dim"]=>
    int(2)
    ["content"]=>
    array(2) {
      ["value"]=>
      string(1) "4"
      ["description"]=>
      string(1) "4"
    }
  }
  [5]=>
  object(subelements)#12 (4) {
    ["veiw"]=>
    string(4) "list"
    ["position"]=>
    string(3) "dir"
    ["dim"]=>
    int(1)
    ["content"]=>
    array(2) {
      ["value"]=>
      string(15) "Бетонные работы"
      ["description"]=>
      string(0) ""
    }
  }
  [6]=>
  object(subelements)#13 (4) {
    ["veiw"]=>
    string(4) "list"
    ["position"]=>
    string(4) "word"
    ["dim"]=>
    int(2)
    ["content"]=>
    array(2) {
      ["value"]=>
      string(1) "5"
      ["description"]=>
      string(1) "5"
    }
  }
  [7]=>
  object(subelements)#14 (4) {
    ["veiw"]=>
    string(4) "list"
    ["position"]=>
    string(4) "word"
    ["dim"]=>
    int(2)
    ["content"]=>
    array(2) {
      ["value"]=>
      string(1) "6"
      ["description"]=>
      string(1) "6"
    }
  }
  [8]=>
  object(subelements)#15 (4) {
    ["veiw"]=>
    string(4) "list"
    ["position"]=>
    string(4) "word"
    ["dim"]=>
    int(2)
    ["content"]=>
    array(2) {
      ["value"]=>
      string(1) "7"
      ["description"]=>
      string(1) "7"
    }
  }
  [9]=>
  object(subelements)#16 (4) {
    ["veiw"]=>
    string(4) "list"
    ["position"]=>
    string(4) "word"
    ["dim"]=>
    int(2)
    ["content"]=>
    array(2) {
      ["value"]=>
      string(1) "8"
      ["description"]=>
      string(1) "8"
    }
  }
  [10]=>	- А вот здесь начинается бред, при чем, не смотря на то, что i - статичное оно берется в обоих массивах одинаковое, как будто они одновременно создаются.
  array(,,,) {
    [0]=>
    object(subelements)#7 (4) {
      ["veiw"]=>
      string(4) "list"
      ["position"]=>
      string(3) "dir"
      ["dim"]=>
      int(1)
      ["content"]=>
      array(2) {
        ["value"]=>
        string(15) "Земляные работы"
        ["description"]=>
        string(0) ""
      }
    }
    [1]=>
    object(subelements)#8 (4) {
      ["veiw"]=>
      string(4) "list"
      ["position"]=>
      string(4) "word"
      ["dim"]=>
      int(2)
      ["content"]=>
      array(2) {
        ["value"]=>
        string(1) "1"
        ["description"]=>
        string(1) "1"
      }
    }
    [2]=>
    object(subelements)#9 (4) {
      ["veiw"]=>
      string(4) "list"
      ["position"]=>
      string(4) "word"
      ["dim"]=>
      int(2)
      ["content"]=>
      array(2) {
        ["value"]=>
        string(1) "2"
        ["description"]=>
        string(1) "2"
      }
    }
    [3]=>
    object(subelements)#10 (4) {
      ["veiw"]=>
      string(4) "list"
      ["position"]=>
      string(4) "word"
      ["dim"]=>
      int(2)
      ["content"]=>
      array(2) {
        ["value"]=>
        string(1) "3"
        ["description"]=>
        string(1) "3"
      }
    }
    [4]=>
    object(subelements)#11 (4) {
      ["veiw"]=>
      string(4) "list"
      ["position"]=>
      string(4) "word"
      ["dim"]=>
      int(2)
      ["content"]=>
      array(2) {
        ["value"]=>
        string(1) "4"
        ["description"]=>
        string(1) "4"
      }
    }
    [5]=>
    object(subelements)#12 (4) {
      ["veiw"]=>
      string(4) "list"
      ["position"]=>
      string(3) "dir"
      ["dim"]=>
      int(1)
      ["content"]=>
      array(2) {
        ["value"]=>
        string(15) "Бетонные работы"
        ["description"]=>
        string(0) ""
      }
    }
    [6]=>
    object(subelements)#13 (4) {
      ["veiw"]=>
      string(4) "list"
      ["position"]=>
      string(4) "word"
      ["dim"]=>
      int(2)
      ["content"]=>
      array(2) {
        ["value"]=>
        string(1) "5"
        ["description"]=>
        string(1) "5"
      }
    }
    [7]=>
    object(subelements)#14 (4) {
      ["veiw"]=>
      string(4) "list"
      ["position"]=>
      string(4) "word"
      ["dim"]=>
      int(2)
      ["content"]=>
      array(2) {
        ["value"]=>
        string(1) "6"
        ["description"]=>
        string(1) "6"
      }
    }
    [8]=>
    object(subelements)#15 (4) {
      ["veiw"]=>
      string(4) "list"
      ["position"]=>
      string(4) "word"
      ["dim"]=>
      int(2)
      ["content"]=>
      array(2) {
        ["value"]=>
        string(1) "7"
        ["description"]=>
        string(1) "7"
      }
    }
    [9]=>
    object(subelements)#16 (4) {
      ["veiw"]=>
      string(4) "list"
      ["position"]=>
      string(4) "word"
      ["dim"]=>
      int(2)
      ["content"]=>
      array(2) {
        ["value"]=>
        string(1) "8"
        ["description"]=>
        string(1) "8"
      }
    }
    }
  }
}

Большая просьба помочь разобраться - в чем дело, а то тормозится весь проект...
 

Oleg061

Новичок
ЭЭЭЭЭЭЭЭЭЭээ.... Спасибо, конечно, но чем мне это может помочь???
 

AmdY

Пью пиво
Команда форума
В комментариях есть даже реализация, перепишите свой класс по человечески
 

Oleg061

Новичок
Переписал...
PHP:
class subelements
    {
        protected $veiw;
        protected $obj_position;
        protected $obj_dim;
        protected $content=array("value","description","result");
        
        protected static $position="dir";
        protected static $dim=1;
        protected static $i=0;
        
        public function __construct($veiw,
                                    $position,
                                    $dim,
                                    $content=array("value"=>"","description"=>""))
        {
            $this->veiw=$veiw;
            $this->obj_position=$position;
            $this->obj_dim=$dim;
            $this->content=$content;
        }
        /////////////////////////////////////////////////
        public function get_veiw()
        {
            return $this->veiw;
        }
        
        public function set_veiw($veiw)
        {
            $this->veiw=$veiw;
        }
        /////////////////////////////////////////////////
        public function get_obj_position()
        {
            return $this->obj_position;
        }
        
        public function set_obj_position($position)
        {
            $this->obj_position=$position;
        }
        /////////////////////////////////////////////////
        public function get_obj_dim()
        {
            return $this->obj_dim;
        }
        
        public function set_obj_dim($dim)
        {
            $this->obj_dim=$dim;
        }
        /////////////////////////////////////////////////
        public function get_content()
        {
            return $this->content;
        }
        
        public function set_content($content)
        {
            if(is_array($content))
            {
                $i=0;
                foreach($this->content as $key=>$val)
                {
                    $val=$content[$i++];//Протестировать
                }
            }
        }
        /////////////////////////////////////////////////
        public function get_value()
        {
            return $this->content["value"];
        }
        
        public function set_value($value)
        {
            $this->content["value"]=$value;
        }
        /////////////////////////////////////////////////
        public function get_description()
        {
            return $this->content["description"];
        }
        
        public function set_description($description)
        {
            return $this->content["description"]=$description;
        }
        /////////////////////////////////////////////////
        public function get_result()
        {
            return $this->content["result"];
        }
        
        public function set_result($result)
        {
            return $this->content["result"]=$result;
        }
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public static function get_position()
        {
            return self::$position;
        }
        
        public static function change_position($position="")
        {
            if($position)
            {
                self::$position=$position;
            }
            else
            {
                if(self::$position=="dir")   self::$position="file";
                else    self::$position="dir";
            }
            return self::$position;
        }
        
        public static function reset_position()
        {
            self::$position="dir";
        }
        /////////////////////////////////////////////////
        public static function get_dim()
        {
            return self::$dim;
        }
        
        public static function previos_dim()
        {
            return self::$dim--;
        }
        
        public static function next_dim()
        {
            return self::$dim++;
        }
        
        public static function reset_dim()
        {
            self::$dim=1;
        }
        /////////////////////////////////////////////////
        public static function get_index()
        {
            return self::$i;
        }
        
        public static function previos_index()
        {
            return self::$i--;;
        }
        
        public static function next_index()
        {
            return self::$i++;;
        }
        
        public static function reset_index()
        {
            self::$i=0;
        }
        /////////////////////////////////////////////////))))))))))))))
        public static function reset_all()
        {
            self::reset_position();
            self::reset_dim();
            self::reset_index();
        }
    }
Надеюсь, похоже на правду...
Сам метод:
PHP:
protected function list_from_arr($arr)
        {
            $veiw="list";
            
            foreach($arr as $key=>$val)
            {
                if (is_array($val))
                {
                    $content=array("value"=>"$key","description"=>"");
                    subelements::change_position("dir");
                    
                    $i=subelements::get_index();
                    $position=subelements::get_position();
                    $dim=subelements::get_dim();
                    
                    self::$list[$i]=new subelements($veiw,$position,$dim,$content);
                    
                    $dim=subelements::next_dim();
                    $i=subelements::next_index();
                    self::$list[$i]=$this->list_from_arr($val);
                }
                else
                {
                    $content=array("value"=>"$val","description"=>"$key");
                    
                    $i=subelements::get_index();
                    $position=subelements::change_position("file");
                    $dim=subelements::get_dim();
                    
                    self::$list[$i]=new subelements($veiw,$position,$dim,$content);
                    
                    $i=subelements::next_index();
                    continue;
                }
                $dim=subelements::previos_dim();                            
            }
            
            $list_value=self::$list;     
            return $list_value;
        }
Только если раньше он ограничивался одним повторением, теперь пустился в бесконечность...
 

Oleg061

Новичок
Не подскажешь , где???
Дампил $i,$position,$dim - всё нормально. При дампе выходного массива - улетает в космос...
 

zerkms

TDD infected
Команда форума
Значит дампить вообще все переменные после каждого чиха
 

Oleg061

Новичок
Пробывал!!! Благо их не много...

НИЧЕГО!!! Что то в коде не так, что метод на орбиту выводит... Что не пойму...
Какая то конструкция делает вложенные массивы, чего там вообше не предусмотрено... Самое мерзкое, что из за 15 строчек встало всё...
 

Oleg061

Новичок
Примерный дамп результата:
PHP:
array(...) {
  [0]=>
  array(5) {
    [0]=>
    object(subelements)#7 (4) {
      ["veiw:protected"]=>
      string(4) "list"
      ["obj_position:protected"]=>
      string(3) "dir"
      ["obj_dim:protected"]=>
      int(1)
      ["content:protected"]=>
      array(2) {
        ["value"]=>
        string(15) "Земляные работы"
        ["description"]=>
        string(0) ""
      }
    }
    [1]=>
    object(subelements)#8 (4) {
      ["veiw:protected"]=>
      string(4) "list"
      ["obj_position:protected"]=>
      string(4) "file"
      ["obj_dim:protected"]=>
      int(2)
      ["content:protected"]=>
      array(2) {
        ["value"]=>
        string(1) "1"
        ["description"]=>
        string(1) "1"
      }
    }
    [2]=>
    object(subelements)#9 (4) {
      ["veiw:protected"]=>
      string(4) "list"
      ["obj_position:protected"]=>
      string(4) "file"
      ["obj_dim:protected"]=>
      int(2)
      ["content:protected"]=>
      array(2) {
        ["value"]=>
        string(1) "2"
        ["description"]=>
        string(1) "2"
      }
    }
    [3]=>
    object(subelements)#10 (4) {
      ["veiw:protected"]=>
      string(4) "list"
      ["obj_position:protected"]=>
      string(4) "file"
      ["obj_dim:protected"]=>
      int(2)
      ["content:protected"]=>
      array(2) {
        ["value"]=>
        string(1) "3"
        ["description"]=>
        string(1) "3"
      }
    }
    [4]=>
    object(subelements)#11 (4) {
      ["veiw:protected"]=>
      string(4) "list"
      ["obj_position:protected"]=>
      string(4) "file"
      ["obj_dim:protected"]=>
      int(2)
      ["content:protected"]=>
      array(2) {
        ["value"]=>
        string(1) "4"
        ["description"]=>
        string(1) "4"
      }
    }
  }
  [1]=>
  object(subelements)#8 (4) {
    ["veiw:protected"]=>
    string(4) "list"
    ["obj_position:protected"]=>
    string(4) "file"
    ["obj_dim:protected"]=>
    int(2)
    ["content:protected"]=>
    array(2) {
      ["value"]=>
      string(1) "1"
      ["description"]=>
      string(1) "1"
    }
  }
  [2]=>
  object(subelements)#9 (4) {
    ["veiw:protected"]=>
    string(4) "list"
    ["obj_position:protected"]=>
    string(4) "file"
    ["obj_dim:protected"]=>
    int(2)
    ["content:protected"]=>
    array(2) {
      ["value"]=>
      string(1) "2"
      ["description"]=>
      string(1) "2"
    }
  }
  [3]=>
  object(subelements)#10 (4) {
    ["veiw:protected"]=>
    string(4) "list"
    ["obj_position:protected"]=>
    string(4) "file"
    ["obj_dim:protected"]=>
    int(2)
    ["content:protected"]=>
    array(2) {
      ["value"]=>
      string(1) "3"
      ["description"]=>
      string(1) "3"
    }
  }
  [4]=>
  object(subelements)#11 (4) {
    ["veiw:protected"]=>
    string(4) "list"
    ["obj_position:protected"]=>
    string(4) "file"
    ["obj_dim:protected"]=>
    int(2)
    ["content:protected"]=>
    array(2) {
      ["value"]=>
      string(1) "4"
      ["description"]=>
      string(1) "4"
    }
  }
  [5]=>
  array(10) {
    [0]=>
    array(5) {
      [0]=>
      object(subelements)#7 (4) {
        ["veiw:protected"]=>
        string(4) "list"
        ["obj_position:protected"]=>
        string(3) "dir"
        ["obj_dim:protected"]=>
        int(1)
        ["content:protected"]=>
        array(2) {
          ["value"]=>
          string(15) "Земляные работы"
          ["description"]=>
          string(0) ""
        }
      }
      [1]=>
      object(subelements)#8 (4) {
        ["veiw:protected"]=>
        string(4) "list"
        ["obj_position:protected"]=>
        string(4) "file"
        ["obj_dim:protected"]=>
        int(2)
        ["content:protected"]=>
        array(2) {
          ["value"]=>
          string(1) "1"
          ["description"]=>
          string(1) "1"
        }
      }
      [2]=>
      object(subelements)#9 (4) {
        ["veiw:protected"]=>
        string(4) "list"
        ["obj_position:protected"]=>
        string(4) "file"
        ["obj_dim:protected"]=>
        int(2)
        ["content:protected"]=>
        array(2) {
          ["value"]=>
          string(1) "2"
          ["description"]=>
          string(1) "2"
        }
      }
      [3]=>
      object(subelements)#10 (4) {
        ["veiw:protected"]=>
        string(4) "list"
        ["obj_position:protected"]=>
        string(4) "file"
        ["obj_dim:protected"]=>
        int(2)
        ["content:protected"]=>
        array(2) {
          ["value"]=>
          string(1) "3"
          ["description"]=>
          string(1) "3"
        }
      }
      [4]=>
      object(subelements)#11 (4) {
        ["veiw:protected"]=>
        string(4) "list"
        ["obj_position:protected"]=>
        string(4) "file"
        ["obj_dim:protected"]=>
        int(2)
        ["content:protected"]=>
        array(2) {
          ["value"]=>
          string(1) "4"
          ["description"]=>
          string(1) "4"
        }
      }
    }
    [1]=>
    object(subelements)#8 (4) {
      ["veiw:protected"]=>
      string(4) "list"
      ["obj_position:protected"]=>
      string(4) "file"
      ["obj_dim:protected"]=>
      int(2)
      ["content:protected"]=>
      array(2) {
        ["value"]=>
        string(1) "1"
        ["description"]=>
        string(1) "1"
      }
    }
    [2]=>
    object(subelements)#9 (4) {
      ["veiw:protected"]=>
      string(4) "list"
      ["obj_position:protected"]=>
      string(4) "file"
      ["obj_dim:protected"]=>
      int(2)
      ["content:protected"]=>
      array(2) {
        ["value"]=>
        string(1) "2"
        ["description"]=>
        string(1) "2"
      }
    }
    [3]=>
    object(subelements)#10 (4) {
      ["veiw:protected"]=>
      string(4) "list"
      ["obj_position:protected"]=>
      string(4) "file"
      ["obj_dim:protected"]=>
      int(2)
      ["content:protected"]=>
      array(2) {
        ["value"]=>
        string(1) "3"
        ["description"]=>
        string(1) "3"
      }
    }
    [4]=>
    object(subelements)#11 (4) {
      ["veiw:protected"]=>
      string(4) "list"
      ["obj_position:protected"]=>
      string(4) "file"
      ["obj_dim:protected"]=>
      int(2)
      ["content:protected"]=>
      array(2) {
        ["value"]=>
        string(1) "4"
        ["description"]=>
        string(1) "4"
      }
    }
    [5]=>
    object(subelements)#12 (4) {
      ["veiw:protected"]=>
      string(4) "list"
      ["obj_position:protected"]=>
      string(3) "dir"
      ["obj_dim:protected"]=>
      int(1)
      ["content:protected"]=>
      array(2) {
        ["value"]=>
        string(15) "Бетонные работы"
        ["description"]=>
        string(0) ""
      }
    }
    }
И так далее......
 

Oleg061

Новичок
Если убрать $i
PHP:
protected function list_from_arr($arr)
        {
            $veiw="list";
            
            foreach($arr as $key=>$val)
            {
                    if (is_array($val))
                    {
                        $content=array("value"=>"$key","description"=>"");
                        subelements::change_position("dir");
                        
                        $position=subelements::get_position();
                        $dim=subelements::get_dim();
                                                
                        self::$list[]=new subelements($veiw,$position,$dim,$content);
                        
                        $dim=subelements::next_dim();
                        self::$list[]=$this->list_from_arr($val);
                    }
                    else
                    {
                        $content=array("value"=>"$val","description"=>"$key");
                        
                        $position=subelements::change_position("file");
                        $dim=subelements::get_dim();
                        
                        self::$list[]=new subelements($veiw,$position,$dim,$content);

                        continue;
                    }
                    $dim=subelements::previos_dim();                          
            }
 
            return self::$list;     
        }
Результат другой:
PHP:
array(...) {
  [0]=>
  object(subelements)#7 (4) {
    ["veiw:protected"]=>
    string(4) "list"
    ["obj_position:protected"]=>
    string(3) "dir"
    ["obj_dim:protected"]=>
    int(1)
    ["content:protected"]=>
    array(2) {
      ["value"]=>
      string(15) "Земляные работы"
      ["description"]=>
      string(0) ""
    }
  }
  [1]=>
  object(subelements)#8 (4) {
    ["veiw:protected"]=>
    string(4) "list"
    ["obj_position:protected"]=>
    string(4) "file"
    ["obj_dim:protected"]=>
    int(2)
    ["content:protected"]=>
    array(2) {
      ["value"]=>
      string(1) "1"
      ["description"]=>
      string(1) "1"
    }
  }
  [2]=>
  object(subelements)#9 (4) {
    ["veiw:protected"]=>
    string(4) "list"
    ["obj_position:protected"]=>
    string(4) "file"
    ["obj_dim:protected"]=>
    int(2)
    ["content:protected"]=>
    array(2) {
      ["value"]=>
      string(1) "2"
      ["description"]=>
      string(1) "2"
    }
  }
  [3]=>
  object(subelements)#10 (4) {
    ["veiw:protected"]=>
    string(4) "list"
    ["obj_position:protected"]=>
    string(4) "file"
    ["obj_dim:protected"]=>
    int(2)
    ["content:protected"]=>
    array(2) {
      ["value"]=>
      string(1) "3"
      ["description"]=>
      string(1) "3"
    }
  }
  [4]=>
  object(subelements)#11 (4) {
    ["veiw:protected"]=>
    string(4) "list"
    ["obj_position:protected"]=>
    string(4) "file"
    ["obj_dim:protected"]=>
    int(2)
    ["content:protected"]=>
    array(2) {
      ["value"]=>
      string(1) "4"
      ["description"]=>
      string(1) "4"
    }
  }
  [5]=>
  array(5) {
    [0]=>
    object(subelements)#7 (4) {
      ["veiw:protected"]=>
      string(4) "list"
      ["obj_position:protected"]=>
      string(3) "dir"
      ["obj_dim:protected"]=>
      int(1)
      ["content:protected"]=>
      array(2) {
        ["value"]=>
        string(15) "Земляные работы"
        ["description"]=>
        string(0) ""
      }
    }
    [1]=>
    object(subelements)#8 (4) {
      ["veiw:protected"]=>
      string(4) "list"
      ["obj_position:protected"]=>
      string(4) "file"
      ["obj_dim:protected"]=>
      int(2)
      ["content:protected"]=>
      array(2) {
        ["value"]=>
        string(1) "1"
        ["description"]=>
        string(1) "1"
      }
    }
    [2]=>
    object(subelements)#9 (4) {
      ["veiw:protected"]=>
      string(4) "list"
      ["obj_position:protected"]=>
      string(4) "file"
      ["obj_dim:protected"]=>
      int(2)
      ["content:protected"]=>
      array(2) {
        ["value"]=>
        string(1) "2"
        ["description"]=>
        string(1) "2"
      }
    }
    [3]=>
    object(subelements)#10 (4) {
      ["veiw:protected"]=>
      string(4) "list"
      ["obj_position:protected"]=>
      string(4) "file"
      ["obj_dim:protected"]=>
      int(2)
      ["content:protected"]=>
      array(2) {
        ["value"]=>
        string(1) "3"
        ["description"]=>
        string(1) "3"
      }
    }
    [4]=>
    object(subelements)#11 (4) {
      ["veiw:protected"]=>
      string(4) "list"
      ["obj_position:protected"]=>
      string(4) "file"
      ["obj_dim:protected"]=>
      int(2)
      ["content:protected"]=>
      array(2) {
        ["value"]=>
        string(1) "4"
        ["description"]=>
        string(1) "4"
      }
    }
  }
  [6]=>
  object(subelements)#12 (4) {
    ["veiw:protected"]=>
    string(4) "list"
    ["obj_position:protected"]=>
    string(3) "dir"
    ["obj_dim:protected"]=>
    int(1)
    ["content:protected"]=>
    array(2) {
      ["value"]=>
      string(15) "Бетонные работы"
      ["description"]=>
      string(0) ""
    }
  }
  [7]=>
  object(subelements)#13 (4) {
    ["veiw:protected"]=>
    string(4) "list"
    ["obj_position:protected"]=>
    string(4) "file"
    ["obj_dim:protected"]=>
    int(2)
    ["content:protected"]=>
    array(2) {
      ["value"]=>
      string(1) "5"
      ["description"]=>
      string(1) "5"
    }
  }
  [8]=>
  object(subelements)#14 (4) {
    ["veiw:protected"]=>
    string(4) "list"
    ["obj_position:protected"]=>
    string(4) "file"
    ["obj_dim:protected"]=>
    int(2)
    ["content:protected"]=>
    array(2) {
      ["value"]=>
      string(1) "6"
      ["description"]=>
      string(1) "6"
    }
  }
  [9]=>
  object(subelements)#15 (4) {
    ["veiw:protected"]=>
    string(4) "list"
    ["obj_position:protected"]=>
    string(4) "file"
    ["obj_dim:protected"]=>
    int(2)
    ["content:protected"]=>
    array(2) {
      ["value"]=>
      string(1) "7"
      ["description"]=>
      string(1) "7"
    }
  }
  [10]=>
  object(subelements)#16 (4) {
    ["veiw:protected"]=>
    string(4) "list"
    ["obj_position:protected"]=>
    string(4) "file"
    ["obj_dim:protected"]=>
    int(2)
    ["content:protected"]=>
    array(2) {
      ["value"]=>
      string(1) "8"
      ["description"]=>
      string(1) "8"
    }
  }
  [11]=>
  array(11) {
    [0]=>
    object(subelements)#7 (4) {
      ["veiw:protected"]=>
      string(4) "list"
      ["obj_position:protected"]=>
      string(3) "dir"
      ["obj_dim:protected"]=>
      int(1)
      ["content:protected"]=>
      array(2) {
        ["value"]=>
        string(15) "Земляные работы"
        ["description"]=>
        string(0) ""
      }
    }
    [1]=>
    object(subelements)#8 (4) {
      ["veiw:protected"]=>
      string(4) "list"
      ["obj_position:protected"]=>
      string(4) "file"
      ["obj_dim:protected"]=>
      int(2)
      ["content:protected"]=>
      array(2) {
        ["value"]=>
        string(1) "1"
        ["description"]=>
        string(1) "1"
      }
    }
    [2]=>
    object(subelements)#9 (4) {
      ["veiw:protected"]=>
      string(4) "list"
      ["obj_position:protected"]=>
      string(4) "file"
      ["obj_dim:protected"]=>
      int(2)
      ["content:protected"]=>
      array(2) {
        ["value"]=>
        string(1) "2"
        ["description"]=>
        string(1) "2"
      }
    }
    [3]=>
    object(subelements)#10 (4) {
      ["veiw:protected"]=>
      string(4) "list"
      ["obj_position:protected"]=>
      string(4) "file"
      ["obj_dim:protected"]=>
      int(2)
      ["content:protected"]=>
      array(2) {
        ["value"]=>
        string(1) "3"
        ["description"]=>
        string(1) "3"
      }
    }
    [4]=>
    object(subelements)#11 (4) {
      ["veiw:protected"]=>
      string(4) "list"
      ["obj_position:protected"]=>
      string(4) "file"
      ["obj_dim:protected"]=>
      int(2)
      ["content:protected"]=>
      array(2) {
        ["value"]=>
        string(1) "4"
        ["description"]=>
        string(1) "4"
      }
    }
    [5]=>
    array(5) {
      [0]=>
      object(subelements)#7 (4) {
        ["veiw:protected"]=>
        string(4) "list"
        ["obj_position:protected"]=>
        string(3) "dir"
        ["obj_dim:protected"]=>
        int(1)
        ["content:protected"]=>
        array(2) {
          ["value"]=>
          string(15) "Земляные работы"
          ["description"]=>
          string(0) ""
        }
      }
      [1]=>
      object(subelements)#8 (4) {
        ["veiw:protected"]=>
        string(4) "list"
        ["obj_position:protected"]=>
        string(4) "file"
        ["obj_dim:protected"]=>
        int(2)
        ["content:protected"]=>
        array(2) {
          ["value"]=>
          string(1) "1"
          ["description"]=>
          string(1) "1"
        }
      }
     }
    }
  }
 

Oleg061

Новичок
Огромнейшее Вам спасибо!!!
Я просто не был с интераторами знаком.
Я его всё таки победил))
Если любопытно, выкладываю код:
PHP:
protected function list_from_arr($arr)
        {
            $veiw="list";
            
            $list_value=new RecursiveArrayIterator($arr);
            
            for($list_value->rewind();$list_value->valid();$list_value->next())
            {
                if($list_value->hasChildren())
                {
                    $value=$list_value->key($list_value->current());                    
                    
                    $content=array("value"=>"$value","description"=>"");
                    subelements::change_position("dir");
                        
                    $position=subelements::get_position();
                    $dim=subelements::get_dim();
                    
                    self::$list[]=new subelements($veiw,$position,$dim,$content);
                    
                    $dim=subelements::next_dim();
                    $this->list_from_arr($list_value->getChildren());
                }
                else
                {
                    $value=$list_value->key($list_value->current());
                    $description=$list_value->current();
                    
                    $content=array("value"=>"$value","description"=>"$description");
                    
                    $position=subelements::change_position("word");
                    $dim=subelements::get_dim();
                                                
                    self::$list[]=new subelements($veiw,$position,$dim,$content);
                        
                    continue;
                }
                $dim=subelements::previos_dim();  
            }
            
            $list=self::$list;
            return $list;
        }
 

Mols

Новичок
[offtop]
"Загадки рекурсии" - это просто супер))) Лучший сабжект за 5 лет))))
[/offtop]
 
Сверху