array( array('categ"/> array( array('categ">
Home > Backend Development > PHP Tutorial > 请array表现为面包屑

请array表现为面包屑

WBOY
Release: 2016-06-13 13:18:41
Original
875 people have browsed it

请求一个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'=>"第三级")
             )
             )
             )
             )
             )
             )
             ;
Copy after login

可能 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>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template