Friday, August 29, 2025
HomeLanguagesProgram to print multiplication table of any number in PHP

Program to print multiplication table of any number in PHP

In this article, we will see how to print the multiplication table of any given number using PHP. To make the multiplication table, first, we get a number input from the user and then use for loop to display the multiplication table.

We use HTML and PHP to display the multiplication table. The HTML part is used to design a form to get the input from the user and the PHP part is used to execute the multiplication and display the results in table format.

Example:

PHP




<!DOCTYPE html>
<html>
  
<body>
    <center>
        <h1 style="color: green;">
            neveropen
        </h1>
  
        <h3>
            Program to print multiplication<br>
            table of any number in PHP
        </h3>
  
        <form method="POST">
            Enter a number: 
            <input type="text" name="number">
              
            <input type="Submit" 
                value="Get Multiplication Table">
        </form>
    </center>
</body>
  
</html>
  
<?php
if($_POST) {
    $num = $_POST["number"];
  
    echo nl2br("<p style='text-align: center;'>
        Multiplication Table of $num: </p>
    ");
          
    for ($i = 1; $i <= 10; $i++) {
        echo ("<p style='text-align: center;'>$num"
            . " X " . "$i" . " = " 
            . $num * $i . "</p>
        ");
    }
}
?>


Output:

RELATED ARTICLES

Most Popular

Dominic
32249 POSTS0 COMMENTS
Milvus
80 POSTS0 COMMENTS
Nango Kala
6617 POSTS0 COMMENTS
Nicole Veronica
11789 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11838 POSTS0 COMMENTS
Shaida Kate Naidoo
6731 POSTS0 COMMENTS
Ted Musemwa
7011 POSTS0 COMMENTS
Thapelo Manthata
6688 POSTS0 COMMENTS
Umr Jansen
6701 POSTS0 COMMENTS