Skip to content

Instantly share code, notes, and snippets.

@MaheKarim
Created July 16, 2019 20:44
Show Gist options
  • Save MaheKarim/b261ab6883977e15b158df617ff33f9d to your computer and use it in GitHub Desktop.
Save MaheKarim/b261ab6883977e15b158df617ff33f9d to your computer and use it in GitHub Desktop.
<?php
function fibonacci($old, $new, $end){
static $start;
/* Static Variable
* In this function the value of static var value
* won't change
*/
$start = $start ?? 1;
// ?? Ternary Operator Check start value
if($start > $end){
return;
}
$start++;
echo $old." ";
$_temp = $old+$new; // $temp = 0+1
$old = $new; // old = 1
$new = $_temp; // new = 1
fibonacci($old, $new, $end);
}
fibonacci(0,1,5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment