PHP processing Fibonacci Sequence Non-recursive method _php technique

Source: Internet
Author: User
I conceived it myself, and actually the program to solve this thing is an offset problem. First look at the sequence:: 1, 1, 2, 3, 5, 8, 13, 21, 34, the next number of series is the sum of the first 2 digits, and so on.
The program is actually a for statement, the traditional for statement is for ($i =1; $i; $count, $i + +), where the offset is $i= $i +1. If this sequence is processed, the offset is not 1, the first 1 digits. So when you're for, a variable records the previous number, the other record is the current number, the offset is the number, and then the loop is assigned a value, and the last number is recorded as an ex-loop value, which is the offset of the next loop. The code is actually simple:
Copy Code code as follows:

$count = 9999999999967543;
$array = Array (' 0′=>1);
For ($a =1, $i =2; $i < $count; $i = $i + $a) {
$array [] = $a;
$array [] = $i;
$a = $a + $i;
}
Print_r ($array);
echo $count. '. Count ($array). ' The number of Fibonacci sequences ';

Suggest which boring person take this to Phpchina to the Chinese cabbage profession top Pastes

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.