1、下载后盾网的arr
Composer require houdunwang/arr
2、配置文件以供使用
将use houdunwang\\arr\\arr;改成Houdunwang\\Arr\\Arr;
且Arr.php文件和category文件都需要更改。
否则报错non-static method xxx()should not be called statically
class Houdunwang\\Arr\\Arr;不存在
3、使用
在需要使用的model中声明houdunwang\\Arr\\Arr;
在需要用的数组中 用Arr::tree();
下面是使用实例
public function getAll(){Return Arr::tree(db(‘cate’)->order(‘cate_sort desc’)->select(),’cate_name’,$fieldPri=’cate_id’,$fieldPid=’cate_pid’)}