Created
May 1, 2017 23:46
-
-
Save phpfiddle/d360cfded463b433c7a7e792c36548c5 to your computer and use it in GitHub Desktop.
[ Posted by Ino ] For loop exercise
This file contains 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 | |
echo '<pre>'; | |
$msg = ''; | |
for ($i = 1; $i < 10; $i++) { | |
$msg = ''; | |
for ($j = 1; $j < 10; $j++) { | |
$msg .= $i * $j . (($i * $j < 10) ? ' -- ' : ' - '); | |
} | |
echo $msg . '<br>'; | |
} | |
echo '</pre>'; | |
echo '<br> <br> <br>'; | |
echo '<pre>'; | |
$tempArr = array(); | |
$val = 0; | |
for ($i = 1; $i < 10; $i++) { | |
$msg = ''; | |
for ($j = 1; $j < 10; $j++) { | |
$val = $i * $j; | |
if (!in_array($val, $tempArr)) { | |
array_push($tempArr, $val); | |
$msg .= $val . (($val < 10) ? ' -- ' : ' - '); | |
} | |
} | |
echo $msg . '<br>'; | |
} | |
echo '</pre>'; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment