Program to print pyramid pattern in php

1. Write a program to print normal pyramid pattern in php

Solution.

To print normal pyramid pattern in php we need two loops. In first or outer loop will handle numbers of rows and second or inner loop will handle columns for print star ( * ). The php code is given below:

<?php 
/* php program to print 
   simple pyramid 
*/ 
//  function to print pattern
function print_SimplePyramid($n) 
{ 
	// This outer loop handle number
	// of rows in the pyramid 
	for ($r = 0; $r < $n; $r++) 
	{ 		
		// this inner loop
		// handle number of columns 
		// in the pyramid
	 
		for($c = 0; $c <= $r; $c++ ) 
		{ 
        	// print star 
			echo "* "; 
		} 

		// end each row after printing 
		//the star	and start new row	
		echo "</br>";
	} 
} 

	// the number of rows in the pyramid
	$numbeOfRows = 7; 
	print_SimplePyramid($numbeOfRows); 
?> 

OUTPUT:

pyramid pattern in php
Share This!

Leave a Reply

Your email address will not be published.