How to make the number pyramid program in php?

Today, We want to share with you number pyramid program in php.In this post we will show you number pattern programs in php, hear for star pattern in php we will give you demo and example for implement.In this post, we will learn about PHP Nested Forloop – Exercises Pyramid Program Solution with an example.

PHP programs for printing pyramid patterns

Number pattern pyramids in PHP can be printed using for and foreach loop. There are a some of patterns in pyramid pattern. Some of them are display here.

Example 1: Number Pattern

<?php 
function numpat($n) 
{ 
	

	$num = 1; 


	for ($no = 0; $no < $n; $no++) 
	{ 


		for ($x = 0; $x <= $no; $x++ ) 
		{ 
			

			echo $num." "; 
		} 
		

			$num = $num + 1; 


		echo "\n"; 
	} 
} 

	$n = 5; 
	numpat($n); 

?> 

Results

1 
2 2 
3 3 3 
4 4 4 4 
5 5 5 5 5 

Example 2: Character Pattern

<?php 
function alphapat($n) 
{ 
	
	$num = 65; 

	for ($no = 0; $no < $n; $no++) 
	{ 
		
		for ($x = 0; $x <= $no; $x++ ) 
		{ 
			
			$ch = chr($num); 
 
			echo $ch." "; 
		} 

		$num = $num + 1;  
		echo "\n"; 
	} 
} 

	$n = 5; 
	alphapat($n); 
	
?> 

Results

A 
B B 
C C C 
D D D D 
E E E E E 

Example 3: Continuous Character pattern

<?php 

function contalpha($n) 
{ 
	

	$num = 65; 

	for ($no = 0; $no < $n; $no++) 
	{ 
		

		for ($x = 0; $x <= $no; $x++ ) 
		{ 
			

			$ch = chr($num); 


			echo $ch." "; 


			$num = $num + 1; 
		} 

		echo "\n"; 
	} 
} 

	$n = 5; 
	contalpha($n); 
	
?> 

Results

A 
B C 
D E F 
G H I J 
K L M N O 

PHP Program To Print Pyramid

PHP program to Print Pyramid Pattern using * and loop.

<?php
echo "<pre>";
$space = 10;
for ($no = 0; $no <= 10; $no++) {
    
    for ($k = 0; $k < $space; $k++) {
        echo " ";
    }
    for ($x = 0; $x < 2 * $no - 1; $x++) {
        echo "*";
    }
    
    $space--;
    echo "<br/>";
}
echo "</pre>";
?>

I hope you get an idea about alphabet pattern programs in php.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.