PHP无限极分类
2016-02-02 00:20
579 查看
<?php /** * Created by PhpStorm. * User: Administrator * Date: 16-2-1 * Time: 下午11:39 */ namespace Home\Controller; use Think\Controller; class CateController extends Controller{ public function index(){ $arr = array( array( 'id' => 1, 'name' => 'PHP', 'pid' => 0, 'path' => '0' ), array( 'id' => 2, 'name' => 'JAVA', 'pid' => 0, 'path' => '0' ), array( 'id' =>3, 'name' => 'ThinkPHP', 'pid' => 1, 'path' => '0-1' ), array( 'id' =>4, 'name' => 'Spring', 'pid' => 2, 'path' => '0-2' ), ); foreach($arr as &$arr2){ $num = substr_count($arr2['path'],'-'); if($arr2['pid'] > 0){ $pre = '|'.str_repeat('-',$num); }else{ $pre = ''; } $arr2['tree'] = $pre.$arr2['name']; } foreach($arr as $arr3){ $rows[] = $arr3['path'].'-'.$arr3['id']; } array_multisort($rows,$arr);//多数组排序 // print_r($arr); $this->assign('arr',$arr); $this->display(); } } ?>
相关文章推荐
- 必须收藏的23个php实用代码片段
- 必须收藏的php实用代码片段
- PHP开发中常用的十个代码样例
- Mac PHP连接MySQL报错"No such file or directory"
- FTP服务器架设(2)vsftpd 安装
- php中的魔术变量
- mac搭建PHP环境,yii安装
- php.ini 配置详解
- PHP 反射机制Reflection
- php插入转义与查找转义
- phpmyadmin开启远程服务器连接
- 用PHP写出显示客户端IP与服务器IP的代码
- PHP通过SMTP实现发送邮件_包括附件
- 136 php php的启动和关闭
- 在MAC OS上一步一步搭建PHP开发环境
- 织梦在 extend.func.php中函数获取标题拼音?
- PHP curl session 使用
- GatewayWorker教程2
- Composer PHP的包管理器
- phpcms加载系统类与加载应用类之区别详解