thinkphp递归删除子分类
作者:互联网
//删除分类 public function deldir($ids){ $cateId = $this->model->field(array('dir_id','pid'))->select(); $delId = $this->get_all_child($cateId,$ids); $delId[] = $ids; // dd($delId); $where = array( 'dir_id' => array('IN',$delId) ); if(!$this->model->where($where)->delete()){ $this->error('删除失败'); }; $this->success('删除成功'); } //递归获取所有的子分类的ID function get_all_child($array,$id){ $arr = array(); foreach($array as $v){ if($v['pid'] == $id){ $arr[] = $v['dir_id']; $arr = array_merge($arr,$this->get_all_child($array,$v['dir_id'])); }; }; return $arr; }
标签:arr,递归,删除,get,thinkphp,array,id,dir,delId 来源: https://www.cnblogs.com/jwyq/p/16351516.html