star pattern

PHP Star Triangle pattern program

PHP Star Triangle pattern program

In this tutorial, we will discuss about PHP Star Triangle pattern program

Here, we can see four type of star triangle pattern displays using nested for loop in PHP  using stars

 

Code to star Triangle pattern 1

Program 1

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

<?php
//PHP Star Triangle pattern

$rows = 6;//Rows of star triangle
for($i=0; $i<=$rows; ++$i){
    for($j=$rows-$i; $j>=1; --$j){
         echo ("*");//print stars
          echo (" ");// print spaces between stars
    }
       echo "\n";//move to next line
}
 
?>

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

PHP Star Triangle pattern

 

Code to star Triangle pattern 2

Program 2

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

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

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

Star Triangle pattern

 

Code to star Triangle pattern 3

program 3

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

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

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

Star Triangle pattern

 

Code to star Triangle pattern 4

Program 4

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

<?php
//PHP Star Triangle pattern

$rows = 5;//Rows of star triangle
for($i=1; $i<=$rows; ++$i){
    for($j=1; $j<=$i; ++$j){
    }
    for($k=1;$k<=$i;$k++){
         echo ("*");//print stars
          echo (" ");// print spaces between stars
    }
       echo "\n";//move to next line
}
 
?>

 

PHP Star Triangle

 

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

 

PHP Full Pyramid 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

PHP Full Pyramid pattern program

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

1 month ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

9 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

9 months ago

Program for Celsius into Fahrenheit conversion

Program for Celsius into Fahrenheit conversion In this tutorial, we will discuss the concept of…

9 months ago