Last active
February 28, 2017 10:30
-
-
Save alexsunxl/4053be759cbf7ea6e2d18b78022c3a81 to your computer and use it in GitHub Desktop.
php 无限级分类,获得树形数组
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// ... | |
public static function getCategory($pid = 0){ | |
$tmp = Category::where('pid', $pid)->get()->toArray(); | |
$category = []; | |
if (count($tmp) != 0){ | |
foreach ($tmp as $key => $value){ | |
// 通过递归处理获得子类 | |
$value['sub'] = self::getCategory($value['id']); | |
$category[] = $value; | |
} | |
} | |
return $category; | |
} | |
// ... | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment