I don't know much about callbacks. How does the second 1 come from the beginning, and the parameters after 3. I drew a picture, but I still can't imagine how it works.
HUNT
HUNT 2017-08-21 06:32:56
0
2
1098

<?php
function fibonacci($n){
if($n==1 ||$n==2){
return 1;
}else{
return fibonacci($n-1)+fibonacci($n-2);
}
}


for($x=1;$x<=10;$x++){
if ($x==1){
echo '0,';
}
if ($x!=10){
echo fibonacci($x).',';
} else {
echo fibonacci($x);
}
}
?>



HUNT
HUNT

reply all(2)
风豆丁

This is called recursion, not callback

Fibonacci sequence: 1, 1, 2, 3, 5, 8, 13....

The first number, the second value is 1, this is a rule of.

Starting from the third number, the value of the current number is the sum of the previous two numbers. This is the inherent law of the Fibonacci sequence.

Use recursive thinking to find the value of the nth number: fibonacci($n) = fibonacci($n-1)+fibonacci($n-2);

phpcn_u10253

The picture is based on my understanding, I hope it can help you understand better what my problem is

未命名.jpg

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template