Create Pyramid Using asterisks in PHP

$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 '&nbsp;&nbsp;';
		}
	}
	$k = 0;
	while( $k < $diff ){
		echo '*';
		$k++;
	}
	echo '<br/>';
}

OUTPUT:

Leave a Reply

Your email address will not be published. Required fields are marked *