首页 > Web开发 > 详细

PHP无限极分类

时间:2016-02-02 01:16:41      阅读:218      评论:0      收藏:0      [点我收藏+]
<?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();
    }
}
?>

 

PHP无限极分类

原文:http://www.cnblogs.com/finnlee/p/5176610.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!