PHP non-recursive method for processing the Fibonacci series

Source: Internet
Author: User

I thought about it myself. Actually ProgramTo solve this problem, it is an offset problem. 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. CodeIt is actually very simple: Copy codeThe 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.