Project 8: Any Tables in For Loop (like 2,3,4 etc)

Here’s how to create multiplication tables using a PHP for loop :

PHP Code

<?php

$num = 5; // Change this to your desired number

for ($i = 1; $i <= 10; $i++) {

$result = $num * $i;

echo “$num x $i = $result <br>”;

}

?>

Explanation:

  1. We define a variable $num to hold the number for which you want the multiplication table.
  2. The for loop iterates 10 times ($i = 1; $i <= 10; $i++).
  3. Inside the loop, $result calculates the product of $num and the current loop counter $i.
  4. We echo a string displaying the multiplication operation and the result.
  5. <br> adds a line break after each multiplication.

Change $num to any number to generate its multiplication table. This code can be easily modified to create multiplication tables for a range of numbers.

Here’s an example of this :

Output

 

Search

PHP Projects

School Projects

College Projects

Join Us

Recent Blogs