Home >Backend Development >PHP Tutorial >Sharing solutions to problems that arise when PHP returns values recursively_PHP Tutorial
We are using This is what we started writing:
This code looks fine, but in fact there is an else There is something wrong inside. The test executed here has no return value. Therefore, even if the condition $i
<ol class="dp-xml"><li class="alt"><span><span class="tag"><</span><span> ?php </span></span></li><li><span>function test($i) </span></li><li class="alt"><span>{ </span></li><li><span>$i </span><span class="attribute">-</span><span>= </span><span class="attribute-value">4</span><span>; </span></li><li class="alt"><span>if($i </span><span class="tag"><</span><span> </span><span class="tag-name">3</span><span>) </span></li><li><span>{ </span></li><li class="alt"><span>return $i; </span></li><li><span>} </span></li><li class="alt"><span>else </span></li><li><span>{ </span></li><li class="alt"><span>return test($i); //增加return, 让函数返回值 </span></li><li><span>} </span></li><li class="alt"><span>} </span></li><li><span>echo test(30); </span></li><li class="alt"><span class="tag">?></span><span> </span></span></li></ol>
The above code example is the specific solution when there is a problem with PHP's recursive return value.