Example of upstreaming php code
Those who have gone to college in this example should all know the famous "Fibonacci" series, which is about the problem of breeding rabbits. I will give a rough explanation of the question. If a pair of rabbits can have one pair of rabbits each month, and each pair of rabbits can have one pair of rabbits in the first 3rd months after their birth, if from a pair of newborn rabbits, how many rabbits can breed in one year? Train of Thought: in fact, we can divide rabbits into "rabbits in January", "rabbits in February", and "rabbits in March". ① Initial time: a pair of big rabbits in January, with a total of 1 pair. ② First month: in January, the Big Bunny became the big rabbit in February, and the total number was still 1. ③ Second month: in February, the Big Bunny became the big rabbit in March, breeding a pair of rabbits, with a total of 2 pairs. ④ The third month: in March, the big rabbit tmd gave birth to a rabbit. in the month of 1st day of last month, the big rabbit became the big rabbit in February, with a total of three pairs. ............ F0 = 1 F1 = 1 F2 = F0 + F1 F3 = F1 + F2 ...... fn = Fn-2 + Fn-1 look at everyone, is not reflected in the "recurrence" of the core idea, the code is also very simple. */$ Month = 12; $ fab = array (); $ fab [0] = 1; $ fab [1] = 1; for ($ I = 2; $ I <$ month; $ I ++) {$ fab [$ I] = $ fab [$ I-1] + $ fab [$ I-2];} for ($ I = 0; $ I <$ month; $ I ++) {echo sprintf ("Rabbit in {% d} months: {% d }", $ I, $ fab [$ I])."
";}?>