Php non-recursive method for processing the Fibonacci series

Source: Internet
Author: User
Phpchina has a celebrity named "cabbage heart". it is often used as an example. Traditional processing will use recursion to process the Fibonacci series, and the efficiency is slow. However, if he doesn't come up with the answer, it's a bit unfriendly. I have come up with my own ideas. In fact, the program is actually used to solve this problem, which is a problem of offset. First, let's look at the series: the next number in series 1, 1, 2, 3, 5, 8, 13, 21, and 34 is the sum of the first two numbers, and so on.
The program is actually a FOR statement. The traditional FOR statement is for ($ I = 1; $ I; $ count, $ I ++ ), the offset here is $ I = $ I + 1. if the number of rows is processed, the offset is not 1, which is the first number. When you are for, one variable records the previous number, and the other records the current number. The offset is the previous number, and then the value is assigned again in the loop, record the previous number as a loop value of course to offset the next loop. The code is actually very simple:
The code is as follows:
$ Count = 9999999999967543;
$ Array = array ('0' => 1 );
For ($ a = 1, $ I = 2; $ I <$ count; $ I = $ I + $ ){
$ Array [] = $;
$ Array [] = $ I;
$ A = $ a + $ I;
}
Print_r ($ array );
Echo $ count. 'contains'. count ($ array). 'number of Fibonacci series ';

Which of the following boring people is recommended to use phpchina to top up Chinese cabbage jobs?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.