我试图在控制器而不是js中创建html。 有一个数组深度未知的数组。循环里面的递归函数
$tree = $repo->childrenHierarchy();
和一个函数,它读取数组并从数组元素中返回一个html字符串。
public function recursive($tree) {
$html = "";
foreach ($tree as $t) {
$html = $html . '<li> <span><i class="fa fa-lg fa-minus-circle"></i>' . $t['title'] . '</span>';
if ($t['__children'] != null) {
$html = $html . '<ul>';
$this->recursive($t['__children']);
$html = $html . '</ul>';
} else {
$html = $html . '</li>';
}
return $html;
}
我的问题是,我不能保持总字符串,因为每次的函数调用自身的变种HTML被初始化,需持串像全球,但不能图如何。
尝试,但它是initialse $ HTML evrytime –