php - How to return html without break recursive loop -


how concat html , tell php send html in end of recursive loop ?

i have recursive loop build tree table (parent-child) nodes.

functions work want return full html not print it, use return, breaks foreach loop.

 function show_full_tree($ne_id)     {         $store_all_id = array();         $id_result = $this->comment_model->tree_all($ne_id);         foreach ($id_result $comment_id) {             array_push($store_all_id, $comment_id['parent_id']);         }          //echo $this->db->last_query();exit;          $this->in_parent(0,$ne_id, $store_all_id);     }      function in_parent($in_parent,$ne_id,$store_all_id) {      if (in_array($in_parent,$store_all_id)) {         $result = $this->comment_model->tree_by_parent($ne_id,$in_parent);         echo  $in_parent == 0 ? "<ul class='tree'>" : "<ul>";         foreach ($result $re) {             echo " <li class='comment_box'>                 <div class='aut'>".$re['comment_id']."</div>                 <div class='aut'>".$re['comment_email']."</div>                 <div class='comment-body'>".$re['comment_body']."</div>                 <div class='timestamp'>".date("f j, y", $re['comment_created'])."</div>             <a  href='#comment_form' class='reply' id='" . $re['comment_id'] . "'>replay </a>";              $this->in_parent($re['comment_id'],$ne_id, $store_all_id);             echo "</li>";         }         echo  "</ul>";     }  } 

simply make string variable, concat items otherwise print , return after loop finished. used .= operator, shorthand adding new string end of html variable.

function in_parent($in_parent,$ne_id,$store_all_id) {      $html = "";      if (in_array($in_parent,$store_all_id)) {         $result = $this->comment_model->tree_by_parent($ne_id,$in_parent);         $html .=  $in_parent == 0 ? "<ul class='tree'>" : "<ul>";         foreach ($result $re) {             $html .= " <li class='comment_box'>             <div class='aut'>".$re['comment_id']."</div>             <div class='aut'>".$re['comment_email']."</div>             <div class='comment-body'>".$re['comment_body']."</div>             <div class='timestamp'>".date("f j, y", $re['comment_created'])."</div>             <a  href='#comment_form' class='reply' id='" . $re['comment_id'] . "'>replay </a>";             $html .=$this->in_parent($re['comment_id'],$ne_id, $store_all_id);             $html .= "</li>";         }         $html .=  "</ul>";     }      return $html; } 

Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -