I need to create a pyramid using asterisks. I specify a value which becomes the base of the pyramid. The base contains as much asterisks as the value specified and the pyram
You can try
create_pyramid("*", 5);
create_pyramid("@", 10);
create_pyramid("^_^", 10);
function create_pyramid($string, $level) {
echo "";
$level = $level * 2;
for($i = 1; $i <= $level; $i ++) {
if (!($i % 2) && $i != 1)
continue;
print str_pad(str_repeat($string, $i),($level - 1) * strlen($string), " " , STR_PAD_BOTH);
print PHP_EOL;
}
}
Output A
*
***
*****
*******
*********
Output B
@
@@@
@@@@@
@@@@@@@
@@@@@@@@@
@@@@@@@@@@@
@@@@@@@@@@@@@
@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@
Output C
^_^^_^^_^
^_^^_^^_^^_^^_^
^_^^_^^_^^_^^_^^_^^_^
^_^^_^^_^^_^^_^^_^^_^^_^^_^
^_^^_^^_^^_^^_^^_^^_^^_^^_^^_^^_^
^_^^_^^_^^_^^_^^_^^_^^_^^_^^_^^_^^_^^_^
^_^^_^^_^^_^^_^^_^^_^^_^^_^^_^^_^^_^^_^^_^^_^
^_^^_^^_^^_^^_^^_^^_^^_^^_^^_^^_^^_^^_^^_^^_^^_^^_^
^_^^_^^_^^_^^_^^_^^_^^_^^_^^_^^_^^_^^_^^_^^_^^_^^_^^_^^_^