Last active
April 1, 2017 14:30
-
-
Save dailybird/1d653e762db9fe6156008d35829a7653 to your computer and use it in GitHub Desktop.
Print a pyramid.
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 | |
/** | |
* 打印金字塔 | |
* @param [int] $level [层数] | |
* @return [void] | |
*/ | |
function pyramidPrinter($level){ | |
for ($index = 1; $index <= $level; $index++) { | |
for ($space = $level; $space > $index; $space--) { | |
echo "<span style='color:#fff;'>*</span>"; | |
} | |
for ($star = 1; $star <= $index * 2 - 1; $star++) { | |
echo "<span>*</span>"; | |
} | |
for ($space = $level; $space > $index; $space--) { | |
echo "<span style='color:#fff;'>*</span>"; | |
} | |
echo "<br>"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment