需求:需要对数组按照序号逐级显示,下级带缩进。
private function _getCategoryName($data,$kg=‘‘){
static $num = 1;
static $retrun = array();
if(!empty($data)){
foreach ($data as $key => $value){
$retrun[] = $num++.‘.‘.$kg.$value[‘name‘];
if(!empty($value[‘children‘])){
$this->_getCategoryName($value[‘children‘],$kg.‘——‘);
}
}
}
return $retrun;
}
原文:https://www.cnblogs.com/tdalcn/p/12177194.html