I m trying to create html in the controller instead of js. There is an array with unknown depth of arrays.
$tree = $repo->childrenHierarchy();
and a function who reads the array and returns a string of html with values from array elements.
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;
}
My problem is that i cant hold the total string because everytime the function calls itself the var html is initialised, need to hold the string something like global but cant figure how.