类方法返回值,奇怪的现象
本帖最后由 xuzuning 于 2013-03-08 14:59:52 编辑
各位大侠,请看如下代码:
我要实现的功能是,利用一个多维数组输出一个树状结构,下面的参数是多维数组。
//递归树状输出格式一
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | public function accountTreeType1( $arrData ){<br />
<br />
$this ->strLable = $this ->strLable. '<ul>' ;<br />
<br />
foreach ( $arrData as $val ){<br />
<br />
if ( is_array ( $val [ 'child' ])){<br />
$this ->strLable = $this ->strLable. '<li>' . $val [ 'acc_code' ]. $val [ 'acc_name' ];<br />
$this ->accountTreeType1( $val [ 'child' ]);<br />
} else {<br />
<br />
$this ->strLable = $this ->strLable. '<li>' . $val [ 'acc_code' ]. $val [ 'acc_name' ]. '</li>' ;<br />
if ( $val [id]== '最后一个ID' ){<br />
return $this ->strLable;
}<br />
<br />
}<br />
<br />
}<br />
<br />
$this ->strLable = $this ->strLable. '</ul>' ;<br />
<br />
}
|
Copier après la connexion
------解决方案--------------------方法的最后加上
return $this->strLable;
------解决方案-------------------- public function accountTreeType1($arrData){
$strLable .= '
';
foreach($arrData as $val){
if(is_array($val['child'])){
$strLable .= '- '.$val['acc_code'].$val['acc_name'].'
';
$strLable .= $this->accountTreeType1($val['child']);
}else{
$strLable .= '- '.$val['acc_code'].$val['acc_name'].'
';
}
}
return $strLable.'
';
}