您的位置:首页 > 编程语言 > PHP开发

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();
}
}
?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: