Created
January 27, 2018 11:33
-
-
Save Tobur/bccdfa2b80a0f358b1a151be97f432f7 to your computer and use it in GitHub Desktop.
Just pyramids
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 | |
function draw($n) | |
{ | |
for ($i = 1; $i < $n; $i++) { | |
$spaces = $n - $i; | |
for ($j = 0; $j < $spaces; $j++) { | |
echo ' '; | |
} | |
for ($k = 0; $k < $i; $k++) { | |
echo '*'; | |
} | |
for ($r = 1; $r < $i; $r++) { | |
echo '*'; | |
} | |
echo "\n"; | |
} | |
for ($i = $n; $i > 0; $i--) { | |
$spaces = $n - $i; | |
for ($j = 0; $j < $spaces; $j++) { | |
echo ' '; | |
} | |
for ($k = 0; $k < $i; $k++) { | |
echo '*'; | |
} | |
for ($r = 1; $r < $i; $r++) { | |
echo '*'; | |
} | |
echo "\n"; | |
} | |
echo "\n"; | |
echo "\n"; | |
} | |
draw(10); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment