php - recursive function inside for loop -


i m trying create html in controller instead of js. there array unknown depth of arrays.

$tree = $repo->childrenhierarchy(); 

and function reads array , returns string of html values array elements.

 public function recursive($tree) {         $html = "";         foreach ($tree $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 cant hold total string because everytime function calls var html initialised, need hold string global cant figure how.

there shouldnt wrong storing value in class property while action ?

public $html = "";   public function recursive($tree) {         foreach ($tree $t) {             $this->html = $this->html . '<li> <span><i class="fa fa-lg fa-minus-circle"></i>' . $t['title'] . '</span>';             if ($t['__children'] != null) {                 $this->html = $this->html . '<ul>';                 $this->recursive($t['__children']);                 $this->html = $this->html . '</ul>';             } else {                 $this->html = $this->html . '</li>';             }             return $this->html;         } 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -