Hi,
I'm new to PHP and have a small problem. Assume you define a function
that is called with a constant as parameter. Within that function, based
on some condition it calls itself recursively. Example:
<?php
function Test($firstcall ) {
echo "(enter) firstcall=$firs tcall<br>\n";
if (some_condition ) {
Test(0);
}
echo "(leave) firstcall=$firs tcall<br>\n";
}
Test(1);
?>
I need that variable/parameter before and after the main part of the
function. For the first call, the (enter) output shows that $firstcall=1,
but the (leave) always shows $firstcall=0, if the function has been
called recursively. I don't use parameters by reference but by value. So
how must I declare $firstcall correctly to maintain its content within
subsequent calls?
As tha parameter name says, it only should be 1 for the first (= the
outside) call.
Thanks for enlightening a newbie :-)
- Michael
I'm new to PHP and have a small problem. Assume you define a function
that is called with a constant as parameter. Within that function, based
on some condition it calls itself recursively. Example:
<?php
function Test($firstcall ) {
echo "(enter) firstcall=$firs tcall<br>\n";
if (some_condition ) {
Test(0);
}
echo "(leave) firstcall=$firs tcall<br>\n";
}
Test(1);
?>
I need that variable/parameter before and after the main part of the
function. For the first call, the (enter) output shows that $firstcall=1,
but the (leave) always shows $firstcall=0, if the function has been
called recursively. I don't use parameters by reference but by value. So
how must I declare $firstcall correctly to maintain its content within
subsequent calls?
As tha parameter name says, it only should be 1 for the first (= the
outside) call.
Thanks for enlightening a newbie :-)
- Michael
Comment