1. 程式人生 > 其它 >php遞迴呼叫流程分析

php遞迴呼叫流程分析

技術標籤:phpphp

<?php 
function loop($x, $key=false){
     static $i = 0;
     echo $i;
     echo "<br>";
     $i++;
     if($i<10){
         loop($x);
     } else{
	     echo "large than 10";
	     echo "<br>";
    }
	if ($key){
		echo "key is true";
		echo "<br>";
	} else {
		echo "key is false";
		echo "<br>";
	}
	echo "something in loop with i= ".$i;
	echo "<br>";
}

$x=100;
loop($x, true);
?> 

輸出:

0
1
2
3
4
5
6
7
8
9
large than 10
key is false
something in loop with i= 10
key is false
something in loop with i= 10
key is false
something in loop with i= 10
key is false
something in loop with i= 10
key is false
something in loop with i= 10
key is false
something in loop with i= 10
key is false
something in loop with i= 10
key is false
something in loop with i= 10
key is false
something in loop with i= 10
key is true
something in loop with i= 10