Home  >  Article  >  Backend Development  >  php递归。该如何解决

php递归。该如何解决

WBOY
WBOYOriginal
2016-06-13 11:46:42837browse

php递归。
刚才网上看了php递归,又问了问大神,告诉我说递归就是调用它本身。没有听明白。又在百度上看了汉诺塔问题。倒是知道汉诺塔是咋回事了,但是还是不明白递归。望牛人们给个简单易懂的例子。。。
------解决方案--------------------

function f($n)  <br />{  <br />   $out = -1;<br />   if($n<0)<br />       echo "输入不能是负数";<br />   else if($n==0<br><font color='#FF8000'>------解决方案--------------------</font><br>$n==1)<br />       $out=1;<br />   else $out=f($n-1)*$n;  <br />   return $out;<br />}<br />echo f(3);

最经典的例子 阶乘

Statement:
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