
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
PHP program to print a pattern of pyramid
Let us see an example to print a pattern of pyramid in PHP −
Example
<?php function print_pattern($val) { $num = 2 * $val - 2; for ($i = 0; $i < $val; $i++) { for ($j = 0; $j < $num; $j++) echo " "; $num = $num - 1; for ($j = 0; $j <= $i; $j++ ) { echo "* "; } echo "\n"; } } $val = 7; print_pattern($val); ?>
Output
* * * * * * * * * * * * * * * * * * * * * * * * * * * *
A function named ‘print_pattern’ is defined that iterates through the number of rows through which the pattern needs to be generated. Relevant line breaks are also echoed using the ‘echo’ attribute. The function is called by passing the number of rows for which the pattern needs to be generated.
- Related Questions & Answers
- Program to print pyramid pattern in C
- Java Program to Print Pyramid Star Pattern
- Print Pyramid Star Pattern in Java Program
- C Program to print hollow pyramid and diamond pattern
- Program to print hollow pyramid and diamond pattern in C++
- Program to print an inverse pyramid character pattern in C++
- PHP program to print the number pattern
- Java Program to Create Pyramid and Pattern
- PHP program to print continuous character pattern triangle
- Program to print a pattern of numbers in C++
- C++ Programs To Create Pyramid and Pattern
- Java Program to Print Spiral Pattern of Numbers
- Java program to print a given pattern. (stars)
- Program to print a matrix in Diagonal Pattern.
- Program to print a rectangle pattern in C++
Advertisements