多维数组递归分类
<?php
/**
* [recursiveCategory 递归分类信息]
* @author Wongzx <[842687571@qq.com]>
* @param [Int] $[pid] [<父级Id>]
* @param [array] $[list] [<数组>]
* @return array
*/
function recursiveCategory($pid, $list = '') {
static $categoryList;
if ( !empty($list) ) {
$categoryList = $list;
}
$childList = array();
foreach ($categoryList as $key => $value) {
if ( $value['pid'] == $pid ) {
$childList[] = $value;
unset($categoryList[$key]);
}
}
if (empty($childList)) {
return false;
} else {
$result = array();
foreach ($childList as $cvalue) {
$tempResult = $this->recursiveCategory($cvalue['id']);
if (!empty($tempResult)) {
foreach ($tempResult as &$value) {
$value['path'] = $pid . '-' . $value['path'];
}
$cvalue['childCategory'] = $tempResult;
}
$result[] = $cvalue;
}
return $result;
}
}