Pyramid program in PHP

Hello All,

This is kind of fun stuff.

I was bored and decided to build a Pyramid Program in PHP.

<?php 
$max = 5; //any numeric value to be assigned here
for($i=1;$i<=$max;$i++)
{		
	inter($i,$max);	
}
for($i=$max-1;$i>=1;$i--)
{		
	inter($i,$max); 	
}

function sp($j,$max)
{
	for($i=$j;$i<$max;$i++)
	{
		echo '&nbsp;&nbsp;&nbsp;';
	}
}
function inter($i,$max)
{
	$j=1;
	sp($i,$max);
	while ($j<=$i) 
	{		
		echo '&nbsp;'.$j;		
		
		if($j==$i)
		{	
			$m = $j-1;
			while ($m>=1) 
			{
				echo '&nbsp;'.$m;	
				$m--;
			}
		}
		$j++;
	}
	echo '<br/>';
}
?>

Above code on execution will output

pyramid
pyramid

Enjoy 🙂

3 thoughts on “Pyramid program in PHP

  1. hi
    dear
    very good
    now i want script code about html pagination export in ms word
    best regards
    Mohammad

Leave a Reply to Jhone Cancel reply

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

Scroll to top