Pattren printing

PHP Star triangle Pattern program

PHP Star triangle Pattern program

Here’s a simple Java program that demonstrates how to print star triangle patterns using PHP. The PHP Star pattern is created only using for loop

Program 1

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

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

Print Pyramid -PHP

 

Program 2

<?php
//Star Pyramid Size
//PHP pyramid patterns
$row = 6;//define Rows of Pyramid
for($i=$row; $i>=1; --$i){
    for($space=0 ;$space<=$row-$i; ++$space)
        echo (" ");//add 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

 

Program 3

<?php
//Star Pyramid pattern
//PHP pyramid patterns
$size = 7;//Rows of Pyramid
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 Patterns

 

Program 4

<?php
//PHP star triangle patterns
$rows = 10;//Rows of triangle
print("Triangle star pattern\n");
for($i=1; $i<=$rows; $i++){
    for($spaces=1; $spaces<=$i; $spaces++){
        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

Triangle star Patterns

 

Program 5

<?php
//PHP star triangle patterns
$rows = 10;//Rows of triangle
print("Triangle star pattern\n");
for($i=1; $i<=$rows; ++$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

Pyramid Pattern program

 

Program 6

<?php
//PHP star triangle patterns
$rows = 8;//Rows of triangle
print("Triangle star pattern\n");
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

Triangle Star Patterns

 

Program 7

<?php
//PHP star triangle patterns
$rows = 8;//Rows of triangle
print("Triangle star pattern\n");
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
}
 
?>

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

Pyramid Pattern program

 

Suggested post

Pyramid pattern in Java

C pyramid star pattern program – using loops

C++ pyramid star pattern program – using loops

Java pyramid star pattern program – using loops

C program to create an Inverted Pyramid star pattern

C++ program to create an Inverted Pyramid star pattern

Hollow Pyramid star pattern in C language

Hollow Pyramid star pattern in C++ language

Hollow reverse Pyramid pattern in C language

Hollow reverse Pyramid pattern in C+ language

Karmehavannan

Recent Posts

Subtract two numbers using method overriding

Subtract two numbers using method overriding   Program 1

4 weeks ago

Using function or method to Write temperature conversion : Fahrenheit into Celsius

Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…

1 year ago

Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user

Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…

1 year ago

Write temperature conversion program: Fahrenheit into Celsius

Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…

1 year ago

How to write a program to convert Fahrenheit into Celsius

How to write a program to convert Fahrenheit into Celsius In this article, we will…

1 year ago

Function/method to convert Celsius into Fahrenheit -Entered by user

Function/method to convert Celsius into Fahrenheit -Entered by user In this article, we will discuss…

1 year ago

This website uses cookies.