Home  >  Article  >  Backend Development  >  求将一段递归代码改为非递归形式

求将一段递归代码改为非递归形式

WBOY
WBOYOriginal
2016-06-23 13:55:38837browse

function delRecursive($id,$class_arr){	if($id=="") $id=0;	for($i=0;$i<count($class_arr);$i++){		if($class_arr[$i][3]==$id){		    $subid=$class_arr[$i][0];		    $this->db->delete('tree', array('id' => $id));		    $this->db->delete('tree', array('id' => $subid));					delRecursive($subid,$class_arr);		}		}}


回复讨论(解决方案)

你的 $class_arr 是什么样子的?
贴出来看看

$st = array($id);do {                $cnt = count($st);                 for($i=0;$i<count($class_arr);$i++){                    if(in_array($class_arr[$i][3], $st)){                        $subid=$class_arr[$i][0];                            if(!in_array($subid, $st)) {                                $st[] = $subid;                                $this->DB_MT->delete('tree', array('id' => $id));                                $this->DB_MT->delete('tree', array('id' => $subid));                            }                        }                       }}while($cnt < count($st));

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn