PHP
php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
//the Phibonacci sequence starts with 0 and 1, then the next number has to be the sum of the previous 2.
// at first it will be 1, cause 0 + 1 = 1. then 1 + 1 = 2, 2 + 1 = 3, 3 + 2 = 5, 5 + 3 = 8[...]..
// sets the first two values
$st = 0; $nd = 1 ;
echo " $st $nd ";
// sets the next 15 values to be printed
for($i = 0; $i < 15; $i++){
//sets the next value as the sum of the previous 2
$rd = $st + $nd ;
echo "$rd ";
//pushes the values back so the next one can be the sum of the last two
$st = $nd ;
$nd = $rd;
}
?>
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run