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

Multiply two numbers in Java using scanner| 5 different ways

Multiply two numbers in Java using scanner| 5 different ways In this article, we will…

9 months ago

5 different ways to Divide two numbers in Java using scanner

5 Different ways to Divide two numbers in Java using scanner In this article, we…

10 months ago

Learn 8 Ways to Subtract Two Numbers Using Methods in Java

Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…

10 months ago

10 ways to subtract two numbers in Java

10 ways to subtract two numbers in Java In this article, we will discuss the…

10 months ago

Java Code Examples – Multiply Two Numbers in 5 Easy Ways

Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…

10 months ago

How to Divide two numbers in Java| 5 different ways

How to Divide two numbers in Java| 5 different ways In this article, we will…

10 months ago

This website uses cookies.