- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 the number pattern
To print the number pattern in PHP, the code is as follows −
Example
<?php function num_pattern($val) { $num = 1; for ($m = 0; $m < $val; $m++) { for ($n = 0; $n <= $m; $n++ ) { echo $num." "; } $num = $num + 1; echo "
"; } } $val = 6; num_pattern($val); ?>
Output
1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 6 6 6 6 6 6
This is similar to generating a star pattern, the only difference being, numbers are generated instead of stars. The function ‘num_pattern’ is defined that takes the limit as a parameter. The limit value is iterated over and the number is printed and relevant line breaks are also generated in between. The function is called by passing this limit value and the relevant output is generated on the console.
- Related Articles
- PHP program to print a pattern of pyramid
- PHP program to print continuous character pattern triangle
- Program to print number pattern in C
- Python Program to print the pattern ‘G’
- Python Program to Read a Number n and Print the Natural Numbers Summation Pattern
- Golang Program to Read a Number (n) and Print the Natural Numbers Summation Pattern
- Program to print ‘N’ alphabet using the number pattern from 1 to n in C++
- Program to print Interesting pattern in C++
- Program to print Kite Pattern in C++
- Program to print Diamond Pattern in C
- Program to print numeric pattern in C
- Program to print pyramid pattern in C
- Java Program to Print Pyramid Star Pattern
- Java Program to Print Diamond Star Pattern
- Java Program to Print Square Star Pattern

Advertisements