Skip to content

Instantly share code, notes, and snippets.

@SuryaElite
Created February 10, 2017 21:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SuryaElite/283ac3b8c42ebd90aa66ea0dfe84a177 to your computer and use it in GitHub Desktop.
Save SuryaElite/283ac3b8c42ebd90aa66ea0dfe84a177 to your computer and use it in GitHub Desktop.
Funny Problems: Print Stars Vertically
<?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