PHP Tutorial : Generate multiplication table from any number to any number

Generate multiplication table from any number to any number in PHP

We are going to learn PHP code to generate tables from any number to any number up to 10 multiplies.

This tutorial consist of 3 parts : HTML / CSS / PHP

HTML is to display the tables and CSS is to decorate those table. Main part is of PHP which will generate tables from any number to any.

So lets start.

Here in this tutorial to display better output i used Bootstrap so that all tables will come in Col-Sections

<?php
echo '<div class="row container">';

$number1 = 2;
$number2 = 20;

$difference = $number2 - $number1;

for($i=0;$i<=$difference;$i++)
{
    $ar = $number1+$i;
    echo '<div class="col-sm-3 text-center"><div class="box">';
    echo '<div class="box-head">Table Of '.$ar.'</div>';

    for($k=1;$k<=10;$k++)
    {
        echo $ar.'x'.$k.' = '.$ar*$k.'<br />';	
    }

    echo '</div></div>';
}

echo '</div>';
?>

 

Above code will generate tables from 2 to 20 , Table of 2 , 3, 4 …… so on upto 20. And this will display like this given below

php tutorial generate tables

Hope this will help some of our reader.

Have a nice day.

1 thought on “PHP Tutorial : Generate multiplication table from any number to any number

Leave a Reply

Your email address will not be published. Required fields are marked *

  +  78  =  83