当前位置:Gxlcms > PHP教程 > smarty模板解析数组有关问题

smarty模板解析数组有关问题

时间:2021-07-01 10:21:17 帮助过:29人阅读

smarty模板解析数组问题
PHP code
array (
  'id' => 1,
  'pid' => 0,
  'name' => '一级1',
  'child' => 
  array (
    2 => 
    array (
      'id' => 2,
      'pid' => 1,
      'name' => '二级11',
    ),
    3 => 
    array (
      'id' => 3,
      'pid' => 1,
      'name' => '二级12',
    ),
    9 => 
    array (
      'id' => 9,
      'pid' => 1,
      'name' => '二级13',
      'child' => 
      array (
        4 => 
        array (
          'id' => 4,
          'pid' => 9,
          'name' => '三级11',
          'child' => 
          array (
            5 => 
            array (
              'id' => 5,
              'pid' => 4,
              'name' => '四级13',
            ),
            7 => 
            array (
              'id' => 7,
              'pid' => 4,
              'name' => '四级11',
            ),
            8 => 
            array (
              'id' => 8,
              'pid' => 4,
              'name' => '四级12',
              'child' => 
              array (
                10 => 
                array (
                  'id' => 10,
                  'pid' => 8,
                  'name' => '五级分类',
                  'child' => 
                  array (
                    11 => 
                    array (
                      'id' => 11,
                      'pid' => 10,
                      'name' => '六级分类',
                    ),
                  ),
                ),
              ),
            ),
          ),
        ),
        6 => 
        array (
          'id' => 6,
          'pid' => 9,
          'name' => '三级21',
        ),
      ),
    ),
  ),
)



这种数组在smarty里怎么做处理成树状结构??

------解决方案--------------------
是用JS做的吧,如果smarty能做,那么PHP就能
------解决方案--------------------
我想知道干嘛
------解决方案--------------------
smarty2 不可以
smarty3 可以,模板中又递归函数

人气教程排行