In this post, you will learn about writing coding for number tables in PHP. This number table is very useful for Kids, so by using this code you can create a number table app or webpage for kids, they can enter any number and within a second they can get a number table for practice.
In the below code, you can take a number variable for a static number table, let’s take 9 , then simply using for each loop you can print the Table of Numbers easily.
If you want a dynamic number table, then use an HTML form and input field with submit button, so that after entering any number you can get a number table of that number.
Step-1: Code for Number Table
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <?php $var=9; $row=0; for($i=1;$i<=10;$i++) { $row=$var*$i; echo $var; echo"*"; echo $i; echo "="; echo $row; echo "<hr>"; } ?> |
Output-
9*1=9
9*2=18
9*3=27
9*4=36
9*5=45
9*6=54
9*7=63
9*8=72
9*9=81
9*10=90
Dynamic Number Table
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | <!DOCTYPE html> <html> <body> <form Method="post"> Enter number:<input type="text" name="value"/><br><br> <input type="submit" name="btn" value="print table" /> </form> <?php if(isset($_POST['btn'])) { $var=$_POST['value']; $var=9; $row=0; for($i=1;$i<=10;$i++) { $row=$var*$i; echo $var; echo"*"; echo $i; echo "="; echo $row; echo "<hr>"; } } ?> </body> </html> |
Live Demo-1: You can enter any number to get Number Table