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
$n = 5;
for($i = $n; $i >= 1; $i--){
for($j = 1; $j <= $i; $j++){
if($j < $i){
echo '0';//you can replace 0 with space
}else{
$num = $n - $i;
for($k = 0; $k <= $num; $k++){
echo '*';
}
for($y = 1; $y <= $n - 1; $y++){
if($y <= $num){
echo '*';
}else{
echo '0';//you can replace 0 with space
if($y == $n - 1){
echo '<br/>';
}
}
}
}
}
}
function create_piramide ($filas) {
$n = $filas;
echo '<pre>';
for ($i = $filas; $i >= 0; $i--) {
echo str_repeat(' ', $i).str_repeat('o ', $n - $i)."\n";
}
echo '</pre>';
}
create_piramide (10);