Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c

PHP Star triangle Pattern program

Posted on August 22, 2024

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

PHP Star triangle Pattern program
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

PHP Star triangle Pattern program

 

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 Star triangle Pattern program
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

PHP Star triangle Pattern program
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

PHP Star triangle Pattern program
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

PHP Star triangle Pattern program
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

PHP Star triangle Pattern program
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

Related

Recent Posts

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes