star pattern

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program

In this tutorial, we will discuss about PHP Full Pyramid pattern program

Here, we can see three type of pyramid pattern displays using nested for loop in PHP using stars

 

Code to star Pyramid pattern 1

Program 1

Here, we are providing a inverted star pyramid pattern using for loop in PHP programming language

<?php
//Star Pyramid Size
//PHP pyramid patterns
$rows = 7;//Rows of Pyramid
for($i=$rows; $i>=1; --$i){
    for($space=0 ;$space<=$rows-$i; ++$space)
        echo (" ");//print initial spaces
    
    for($j=$i; $j<=2*$i -1 ;$j++)
        
                print ("* ");//print stars
                
       echo "\n";//move to next line
}
 
?>

When the above code is executed, it produces the following result

Pyramid pattern

 

 

 

Code to star Pyramid pattern 2

Program 2

Here, we are providing a star pyramid pattern using for loop in PHP programming language

<?php
//PHP  Star Pyramid pattern
$size = 6;
for($i=1;$i<=$size;$i++){
    for($j=1;$j<=$i; $j++){
        echo("*");//print star
    }
    echo "\n";//move to next line
    }
    for($i=$size; $i>=1; $i--){
    for($j=1; $j<=$i; $j++){
    echo("*");//print star
     }
       echo "\n"; //move to next line      
    }
 
?>

When the above code is executed, it produces the following result

PHP Pyramid pattern

 

Code to star Pyramid pattern 3

Program 3

<?php
//Star Pyramid Size
//PHP pyramid patterns
$rows = 6;//Rows of Pyramid
for($i=1; $i<=$rows; ++$i){
    for($space=$rows; $space>$i; --$space)
        echo (" ");//print initial spaces
    
    for($j=1; $j<=$i ;$j++)
    {
                print ("* ");//print stars
           }     
       echo "\n";//move to next line
}
 
?>

 

Pyramid pattern – PHP

 

 

Suggested for you

Java program to print star pyramid pattern 

C program to print star pyramid pattern 

C++ program to print star pyramid pattern 

Python program to print star pyramid pattern 

Triangle star pattern in Java language

Triangle star pattern in C language

Triangle star pattern in C++ language

 

For loop in C++ language

For loop in Java language

For loop in C language

For loop in Python language

 

Nested for loop in Java language

Nested for loop in C++ language

Nested for loop in C language

Nested for loop in Python language

 

Python Full Pyramid star pattern program
PHP Star Triangle pattern program
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago

Java program to check odd or even using recursion

Java program to check odd or even using recursion In this tutorial, we discuss a…

2 months ago