Use 2 ‘for loops’ with conditions and a ‘while loop’ like the one below. You must specify the pyramid’s height using a variable like $height = 5; first.
$height = 5;
for( $i=$height; $i>=1; $i-- ){
for( $j=1; $j<=$height; $j++ ){
if( $j >= $i ){
echo '*';
if( $j == $height ){
$diff = $j - $i;
}
}else{
echo ' ';
}
}
$k = 0;
while( $k < $diff ){
echo '*';
$k++;
}
echo '<br/>';
}
OUTPUT: