Skip to content

Instantly share code, notes, and snippets.

@EdixonAlberto
Created September 22, 2020 23:47
Show Gist options
  • Save EdixonAlberto/60f52507d7d343b344e10dea3b875003 to your computer and use it in GitHub Desktop.
Save EdixonAlberto/60f52507d7d343b344e10dea3b875003 to your computer and use it in GitHub Desktop.
Algorithm of Fibonacci in php
<?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