Home > Backend Development > PHP Tutorial > Sharing solutions to problems that arise when PHP returns values ​​recursively_PHP Tutorial

Sharing solutions to problems that arise when PHP returns values ​​recursively_PHP Tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-15 13:30:39
Original
1007 people have browsed it

We are using This is what we started writing:

  1. < ?php
  2. function test($i)
  3. {
  4. $i -= 4;
  5. if($i < 3)
  6. {
  7. return $i;
  8. }
  9. else
  10. {
  11. test($i);
  12. }
  13. }
  14. echo test(30);
  15. ?>

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>
Copy after login

The above code example is the specific solution when there is a problem with PHP's recursive return value.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446281.htmlTechArticleWe are using this to start writing: ?php functiontest($i) { $i - = 4; if ($i 3 ) { return$i; } else { test($i); } } echotest(30); ? This code seems to have no problem, but in fact...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template