Created
September 22, 2020 23:47
-
-
Save EdixonAlberto/60f52507d7d343b344e10dea3b875003 to your computer and use it in GitHub Desktop.
Algorithm of Fibonacci in php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function fibonacci(int $serie): array { | |
$firstNro = 0; | |
$secondNro = 1; | |
$arraySequence = [0]; | |
for ($i=1; $i <= $serie; $i++) { | |
$suma = $firstNro + $secondNro; | |
$arraySequence[$i] = $suma; | |
$firstNro = $secondNro; | |
$secondNro = $suma; | |
} | |
return $arraySequence; | |
} | |
$result = fibonacci(10); | |
print_r($result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment