Created
February 10, 2017 21:18
-
-
Save SuryaElite/283ac3b8c42ebd90aa66ea0dfe84a177 to your computer and use it in GitHub Desktop.
Funny Problems: Print Stars Vertically
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 | |
$values = array(2,4,1,3,1,9); | |
$max = max($values); | |
$count = count($values); | |
$finalString = ""; | |
for ($i = 0 ; $i < $max; $i++) { | |
for($j = 0; $j < $count ; $j++) { | |
$values[$j] < ($max - $i) ? $finalString .= " " : $finalString .= " * "; | |
} | |
$finalString .= "\n"; | |
} | |
echo $finalString; | |
// Result | |
// * | |
// * | |
// * | |
// * | |
// * | |
// * * | |
// * * * | |
// * * * * | |
// * * * * * * |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment