GeeksforGeeks App
Open App
Browser
Continue

# PHP programs for printing pyramid patterns

Simple Pyramid Pattern

## PHP



Output :

*
* *
* * *
* * * *
* * * * *

Time Complexity: The time complexity of this algorithm is O(N^2) where N is the number of rows.

Space Complexity: The space complexity of this algorithm is O(1) because only a fixed amount of memory is used.

After 180 degree rotation

## PHP



Output :

*
* *
* * *
* * * *
* * * * *

Time Complexity: O(N^2) where N is the number of rows.

Space Complexity: O(1) because only a fixed amount of memory is used.

Printing Triangle

## PHP



Output :

*
* *
* * *
* * * *
* * * * *

Time complexity: O(N^2) where N is given number of rows
Auxiliary Space: O(1)

Star Triangle Pattern 2

## PHP

 =1;\$i--){ for(\$j = 1; \$j < \$i; ++\$j) {  \$pyramid_str.=\$string." "; } \$pyramid_str.="\r\n";} return \$pyramid_str;}echo triangle_pattern(9);?>

Output

*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*

Time Complexity: O(n^2), where n is the input parameter.

Space Complexity: O(n), where n is the input parameter.

Number Pattern

## PHP



Output:

1
2 2
3 3 3
4 4 4 4
5 5 5 5 5

Numbers without re assigning

## PHP



Output:

1
2 3
4 5 6
7 8 9 10
11 12 13 14 15

Character Pattern

## PHP



Output:

A
B B
C C C
D D D D
E E E E E

Continuous Character pattern

## PHP



Output:

A
B C
D E F
G H I J
K L M N O

Time complexity: O(n^2) where N is given input no of rows
Auxiliary Space: O(1)

PHP is a server-side scripting language designed specifically for web development. You can learn PHP from the ground up by following this PHP Tutorial and PHP Examples.

My Personal Notes arrow_drop_up