Powers of 11 Number Pattern in PHP

Beginner
⏱️ 4 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
Loop + Multiplication

What You’ll Learn

How to print a powers-of-11 number pattern in PHP using a simple for loop and repeated multiplication.

This is a compact loop exercise that demonstrates state updates across iterations.

⭐ Pattern Output

For 5 rows, the pattern looks like this:

Output
1
11
121
1331
14641
1

Complete PHP Program

Start with $k = 1 and multiply by 11 on each row after the first.

PHP
<?php
$k = 1;
for ($i = 1; $i <= 5; $i++) {
    if ($i == 1) {
        $k = $i;
    } else {
        $k = $k * 11;
    }
    echo $k . PHP_EOL;
}

🧠 How It Works

1

Initialize value

$k = 1; stores the current term.

Setup
2

Loop through rows

for ($i = 1; $i <= 5; $i++) controls how many terms to print.

Row count
3

Update term

First row keeps 1. After that, $k = $k * 11; generates the next value.

State update
4

Print output

echo $k . PHP_EOL; prints one term per line.

Display
=

Powers of 11 sequence

The loop does n iterations, so runtime is O(n) for n rows.

2

Variation — User Input (CLI) Version

This version takes number of rows from user input (run from terminal with php):

PHP
<?php
echo "Enter number of rows: ";
$rows = (int) trim(fgets(STDIN));

if ($rows < 1) {
    echo "Rows must be at least 1" . PHP_EOL;
    exit;
}

$k = 1;
for ($i = 1; $i <= $rows; $i++) {
    if ($i == 1) {
        $k = 1;
    } else {
        $k *= 11;
    }
    echo $k . PHP_EOL;
}

💡 Tips for Enhancement

Try These

  • Use big integer libraries for many rows (avoid overflow)
  • Compare output with direct power calculation pow(11, n)
  • Format output in columns for readability
  • Generate related sequences (powers of 2, powers of 3, etc.)
  • Store terms in an array and reuse in UI/table views

Avoid

  • Assuming no overflow for very large row counts
  • Skipping input validation for negative/zero rows
  • Confusing powers-of-11 with exact Pascal rows for large n
  • Using browser-only line breaks in CLI-focused examples

Key Takeaways

1

Each new row multiplies the previous term by 11.

2

The first five terms are 1, 11, 121, 1331, 14641.

3

Runtime is linear in row count (O(n)).

4

The same loop pattern works for other geometric progressions.

❓ Frequently Asked Questions

Because 11^0 = 1, which is the first term of the sequence.
Yes. Increase loop limit or take input from user. For very large rows, use big-integer support.
Only for early rows. Larger powers involve digit carries, so representation differs from raw binomial coefficients.
O(n) iterations for n rows, not counting big-number arithmetic costs.

Explore More PHP Number Patterns!

Keep practicing with sequence-based and loop-based number problems.

All Number Patterns →
Did you know?

The first few powers of 11 visually resemble Pascal triangle rows, which is why this quick pattern is often used in math-programming demos.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful