php递归。该如何解决

WBOY
Release: 2016-06-13 11:46:42
Original
836 people have browsed it

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

最经典的例子 阶乘

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template