Regarding to return function
Posted: Fri May 16, 2003 5:50 am
Dear all,
I have encountered a problem regarding to how to return the value back to the calling function.
This is the code that i used to test the problem.
The "$str" is empty. It does not pass the value back to the calling function.
However, if i comment this line "test ($num, $cnt);", it returns the value back to the calling function.
The "$str" is 4.
Please help. Thanks in advance.
I have encountered a problem regarding to how to return the value back to the calling function.
This is the code that i used to test the problem.
Code: Select all
<?php
function test ($num, $cnt)
{
if($cnt == $num){
return $cnt;
}
else{
$cnt+=1;
test ($num, $cnt);
}
}
$str = test (4, 3);
echo $str;
?>However, if i comment this line "test ($num, $cnt);", it returns the value back to the calling function.
The "$str" is 4.
Code: Select all
<?php
function test ($num, $cnt)
{
if($cnt == $num){
return $cnt;
}
else{
$cnt+=1;
//test ($num, $cnt);
}
}
$str = test (4, 4);
echo $str;
?>