Last active
July 17, 2019 18:43
-
-
Save MaheKarim/b056a91ff492c63660646039115b6b19 to your computer and use it in GitHub Desktop.
While Loop In Fibonacci
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 | |
/** | |
* Created by PhpStorm. | |
* User: Mahe | |
* Date: 17-Jul-19 | |
* Time: 11:54 PM | |
*/ | |
function fibonacci ($number){ | |
static $oldValueStore = 0; // store as static var because the value of this var won't change | |
static $newValueStore = 1; | |
$counter = 0 ; | |
while ($counter < $number){ | |
echo " ".$oldValueStore; | |
$_temporary = $oldValueStore + $newValueStore; | |
$oldValueStore = $newValueStore; | |
$newValueStore = $_temporary; | |
$counter++; | |
} | |
} $number = 6; // Input | |
fibonacci($number); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment