Heim >Backend-Entwicklung >PHP-Tutorial >关于php递归函数的问题
<?phpfunction draw($total,$line=1,$result="a1"){ echo "<script>alert('$total,$line')</script>"; if($line>$total){ return; } else{ $line++; //echo $result; echo "<script>alert('draw1($total,$line,$result)')</script>"; draw($total,$line,$result); echo "<script>alert('draw2($total,$line,$result)')</script>"; } echo $result;}draw(3);?>
没有原因,因为他并没有变
function draw($total,$line=1,$result="a1"){ echo "<script>alert('$total,$line')</script>"; if($line>$total){ return; } else{ $line++; //echo $result; echo "<script>alert('draw1($total,$line,$result)')</script>";echo "递归前 line = $line\n"; draw($total,$line,$result);echo "递归后 line = $line\n"; echo "<script>alert('draw2($total,$line,$result)')</script>"; } echo $result;}draw(3);
谢谢,我想我递归的原理还没弄明白,再去找下资料吧