为什么代码在 class类下就实现不了递归呢?
private $tree = []; public function diggn($pid=0,$span = 0){ $span += 2; $sql = "SELECT * from `car_deepclassify` where `pid` = {$pid} order by `createtime` desc"; $results = $this->db->query($sql)->result_array(); // var_dump($_POST);exit; foreach ($results as $key => $result) { // $result['catename'] = $send = $this->db->where('id',$result['id'])->get('car_deepclassify')->row_array(); $send['catename'] = str_repeat(' ',$span).'|--'.$result['catename']; $this->tree[] = $send; $this->diggn($result['id'],$span); } } public function diguiceshi(){ $this->diggn(); echo '<pre>'; print_r($this->tree); echo '</pre>'; }
像老师那样为啥实现不了 ,只能这样实现呢???(框架ci)