Last active
November 15, 2019 14:27
-
-
Save adeguntoro/da5a7048e9819d0caaf18067e574379b to your computer and use it in GitHub Desktop.
php Looping
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 | |
$f = new NumberFormatter("id", NumberFormatter::SPELLOUT); | |
echo "#####################<br>"; | |
echo $f->format(5)."<br>"; | |
$a = $f->format(169); | |
$pisah = explode(" ", $a); | |
echo "#####################<br>"; | |
echo "foreach array<br>"; | |
foreach($pisah as $key) { | |
echo $key.'<br/>'; | |
} | |
echo "#####################<br>"; | |
echo "For loops<br>"; | |
for ($i = 0; $i <=5; ++$i) { | |
echo $i." = ".$f->format($i)."<br>"; | |
} | |
echo "#####################<br>"; | |
echo "While<br>"; | |
$x = 1; | |
while($x <= 5) { | |
echo "The number is: $x <br>"; | |
$x++; | |
} | |
echo "#####################<br>"; | |
echo "Do While<br>"; | |
$x = 1; | |
do { | |
echo "The number is: $x <br>"; | |
$x++; | |
} while ($x <= 5); | |
function Fibonacci($n){ | |
$num1 = 0; | |
$num2 = 1; | |
$counter = 0; | |
while ($counter < $n){ | |
echo ' '.$num1; | |
$num3 = $num2 + $num1; | |
$num1 = $num2; | |
$num2 = $num3; | |
$counter = $counter + 1; | |
} | |
} | |
// Driver Code | |
$n = 10; | |
Fibonacci($n); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment