PHP Program to Display Multiplication Table

You are Here:

Using for Loop

In the following example, we will create and display the Multiplication Table for the given number (9) using for loop

Example

PHP Compiler
<?php $table = 9; $length = 10; $i = 1; echo "Multiplication table: $table <br>"; for($i=1; $i<=$length; $i++) echo "$i * $table = ".$i * $table. "<br>"; ?>

Output

Multiplication table: 9 1 * 9 = 9 2 * 9 = 18 3 * 9 = 27 4 * 9 = 36 5 * 9 = 45 6 * 9 = 54 7 * 9 = 63 8 * 9 = 72 9 * 9 = 81 10 * 9 = 90

Using while Loop

In the following example, we will create and display the Multiplication Table for the given number (9) using while loop

Example

PHP Compiler
<?php $table = 9; $length = 10; $i = 1; echo "Multiplication table: $table <br>"; while($i <= $length) { echo "$i * $table = ".$i * $table. "<br>"; $i++; } ?>

Output

Multiplication table: 9 1 * 9 = 9 2 * 9 = 18 3 * 9 = 27 4 * 9 = 36 5 * 9 = 45 6 * 9 = 54 7 * 9 = 63 8 * 9 = 72 9 * 9 = 81 10 * 9 = 90

Using do while Loop

In the following example, we will create and display the Multiplication Table for the given number (9) using do while loop

Example

PHP Compiler
<?php $table = 9; $length = 10; $i = 1; echo "Multiplication table: $table <br>"; do{ echo "$i * $table = ".$i * $table ."<br>"; $i++; }while($i <= $length); ?>

Output

Multiplication table: 9 1 * 9 = 9 2 * 9 = 18 3 * 9 = 27 4 * 9 = 36 5 * 9 = 45 6 * 9 = 54 7 * 9 = 63 8 * 9 = 72 9 * 9 = 81 10 * 9 = 90

Reminder

Hi Developers, we almost covered 90% of String functions and Interview Question on PHP with examples for quick and easy learning.

We are working to cover every Single Concept in PHP.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author