Blogger Information
Blog 26
fans 0
comment 3
visits 20875
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
项目笔记--栏目输出
无意苦争春的博客
Original
710 people have browsed it

在项目进行时,忽然碰到了输出栏目这样的刻碟事,原始数据是这样的,类似一个递归实现

当看到这张表是我是绝望的,我不会啊

图片1.png

然后翻了很多页面,终于找到了一些解决方法,分享一下也是给自己做个笔记.当然这是TP5里面的

 //头部导航栏
       $navigation= Db::table('cate')->select();
       $newArray=[];
       foreach($navigation as $row){
           if($row['pid']==0){
               $newArray[]=$row;
               
           }
       }
       foreach($navigation as $row){
           foreach($newArray as $key=>$newrow){
               if($row['pid']==$newrow['id']){
                   $newArray[$key]['app'][]=$row;
               }
               
           }
           
           
       }
       print_r($newArray);


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post