Welcome to the Linux community forum and interact with 2 million technical staff. When we use PHP recursion, we will encounter various problems, what is annoying is the issue with PHP recursive return values. In fact, it is very easy to think about it. But this simple problem has plagued us for half an afternoon. The problem lies in the return of recursive functions.
Welcome to the Linux community forum and interact with 2 million technical staff> when we use PHP recursion, we will encounter various problems, what is annoying is the issue with PHP recursive return values. In fact, it is very easy to think about it. But this simple problem has plagued us for half an afternoon. The problem lies in the return of recursive functions.
Welcome to the Linux community forum and interact with 2 million technicians>
When we use PHP recursion, we will encounter various problems, among which the most distressing is the problems related to PHP recursive return values. In fact, it is very easy to think about it. But this simple problem has plagued us for half an afternoon. The problem lies in the return value of recursive functions.
This is the beginning of writing:
The Code is as follows:
Function test ($ I)
{
$ I-= 4;
If ($ I <3)
{
Return $ I;
}
Else
{
Test ($ I );
}
}
Echo test (30 );
?>
This Code seems to be okay. In fact, there is a problem in else. The test executed here does not return a value. Therefore, even if the condition $ I <3 is met, the return $ I function does not return a value. The above PHP recursive return value function is modified as follows:
The Code is as follows:
<? Php
Function test ($ I)
{
$ I-= 4;
If ($ I <3)
{
Return $ I;
}
Else
{
Return test ($ I); // Add return to let the function return values.
}
}
Echo test (30 );
?>
The above code example is the specific solution to the problem of PHP recursive return values.