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

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-23 13:55:38
Original
872 people have browsed it

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);		}		}}
Copy after login


回复讨论(解决方案)

你的 $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));
Copy after login

Related labels:
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template