I was wondering to know is it possible to create star pyramid using switch case.
Asked
Active
Viewed 409 times
-4
-
Short answer: probably. Do you have any attempt to share with us? – Frédéric Hamidi Feb 18 '14 at 10:04
-
”; } ?> – शु-Bham Feb 18 '14 at 10:06
-
2You keep failing to tag the language you are using on your questions. Stack Overflow is not just for PHP. Please tag your questions properly. Read and study [this page](http://stackoverflow.com/help/how-to-ask) carefully. Thanks. – Lightness Races in Orbit Feb 18 '14 at 10:07
1 Answers
2
If you don't use any loop or recursion, i think this is a solution for your query.
<?php
function star($star){
switch($star){
case '1':
return '* ';
break;
case '2':
return '* * ';
break;
case '3':
return '* * * ';
break;
case '4':
return '* * * * ';
break;
case '5':
return '* * * * * ';
break;
default :
break;
}
}
echo star('1')."<br>".star('2')."<br>".star('3')."<br>".star('4')."<br>".star('5');
?>

Vivek Tomar
- 586
- 4
- 12