Consider below code :
<?php
function test() {
static $count = 0;
$count++;
echo $count."<br>";
if($count < 2) {
test();
echo "In last line...".$count."<br>";
}
$count--;
echo "Count Value : ".$count."<br>";
}
test();
?>
Output is as below :
1
2
Count Value : 1
In last line...1
Count Value : 0
which is outlined with red colored border.
I want to know after if returning false on becoming $count = 2 the immediately following code line echo "Count Value : ".$count."<br>"; gets executed. Then, it is expected to stop the flow as it's the last statement.
-
Why the program flow is not stopping after printing the line Count Value : 1?
-
Then how the last two lines from the output are generating?
-
Who is calling the
test()function again? -
How does the static variable getting reset to 0 again and printing the last two lines of the output?
Aucun commentaire:
Enregistrer un commentaire