Site Overlay

How to write pyramid & reverse pyramid program in php

Here, we have executed two programs together. First is the pyramid program and second is the reverse pyramid program.

PHP

<?php
$pyramidHeight = 10;
for($a=1; $a<=$pyramidHeight; $a++){	
	for($m=1; $m<=$pyramidHeight-$a; $m++){
		echo "&nbsp;&nbsp;";
	}	
	for($i=1; $i<=$a; $i++){
		echo "*&nbsp;&nbsp;";
	}
	echo "<br/>";
}

$pyramidRHeight = 10;
for($a=$pyramidRHeight; $a>0; $a--){
	for($m= $pyramidRHeight - $a; $m>=1; $m--){
		echo "&nbsp;&nbsp;";
	}
	for($i=$a; $i>0;$i--){
		echo "*&nbsp;&nbsp;";
	}
	echo "<br/>";
}
?>

Pyramid program php