array( array('categ"/> array( array('categ">

Home >Backend Development >PHP Tutorial > 请array表现为面包屑

请array表现为面包屑

WBOY
WBOYOriginal
2016-06-13 13:18:41869browse

请求一个array表现为面包屑?
我有这样一个数组,

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--> $a= array(
             array('category' =>
             array('name'=>"第一级"),'children' => array(
             array('category' =>
             array('name'=>"第二级"),'children' => array(
             array('category' =>
             array('name'=>"第三级")
             )
             )
             )
             )
             )
             )
             ;

可能 array('name'=>"第三级")下还有array('name'=>"第三级" 'children' =>array),这样的积极
想实现 第一级 -> 第二级 ->第三级
后面还有children的就一直显示出来

------解决方案--------------------
PHP code
$a = array(
  array('category' =>
    array('name'=>"第一级"),'children' => array(
      array('category' =>
        array('name'=>"第二级"),'children' => array(
          array('category' =>
            array('name'=>"第三级")
          )
        )
      )
    )
  )
);

function Breadcrumbs($ar) {
  foreach($ar as $row) {
    if(isset($row['category'])) echo $row['category']['name'];
    if(isset($row['children'])) {
      echo ' ';
      Breadcrumbs($row['children']);
    }
  }
}

Breadcrumbs($a); <div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn