php递归函数--遍历

多应用在 栏目多级、无限极调用html

数据库数据如:数据库

id   catname   pid数组

1    关于咱们     0app

2     新闻          0函数

3    公司新闻     2ui

4     行业动态    2spa

 

select读出数据后整理函数 $cate
function digui($cate,$pid=0){code

  foreach($cate as $v){htm

    if($v['pid']==$pid){blog

      $v['child'] = digui($cate,$v['id']);

      $arr[] = $v;
    }
  }

return $arr;

}

至关于不断在循环整个$cate数组。。

遍历html代码

 1          <foreach name="cate" item='app'>
 2             <div class="app">
 3                 <p>
 4                     <strong>{$app.catname}</strong>
 8                 </p>
 9                 <foreach name="app.child" item='action'>
10                     <dl>
11                         <dt>
12                             <strong>{$action.catnaem}</strong>
16                         </dt>
24         </dl>
25           </foreach>
26         </div>
27       </foreach>
相关文章
相关标签/搜索