How to make a print table of any number in PHP

PHP Program to create a print table of any number:

PHP program of multiplication print  table:

Hi, readers here we explain how we can program to create a print table of any number in PHP.

In this tutorial, first of all, we explain the logic behind this and then the full source code in a readable format.So you don’t have to bother anything but the prior knowledge of PHP operators and  for..loop construct will help you a lot.

The logic to create multiplication table:

Table of any number simply means that multiplying the number from 1 to 10.





Simple Example:

Here in this example, we create a form with one text field to enter the desired number to find multiplication table. Then store the number in the variable using PHP and run the for loop 10 times to print the multiplication table by using multiplication operator(*)  and echo statement to display the result.

Full Source Code:

<!Doctype html>
<head><title>Finding Table of any number using PHP</title>
<!--form is created using post method and submiting values itself -->

<form action="" method="post">
Enter a number:
<input type="text" name="number" />
<input type="submit" value="Table" />
<!--end of form-->

<!--php code starts-->
/*Php program to find table of any number*/

// if ($_POST) is true i.e.,checking that the HTML form is submited by the method="post" or not.
 /* collecting the value of input field using $_POST['parameter'] 
 and storing it in the variable. */

 echo "Table of $num: <br>";
 //using for loop to create multiplication table.
 echo "$num*$i=$value<br>";

<!--php code ends-->



OUTPUT of  print table of any number in PHP

print table


Leave a Comment