Friday, January 29, 2016

MULTIPLICATION TABLE: Display Multiplication Table using Loop in PHP

Hey guys! My new article is about displaying a multiplication table for the number 9. The $num contains 9 which will serve as our multiplicand and $i contains value that will serve as a multiplier. $i value starts with one (1) and will increment until 10. In short, 9 will be multiplied starting from 1 until 10 since the value of $i will increment by one (1) every time it enters the loop.

In the code below, I used the while loop but you can achieve it using for loop and even do while loop.

PHP Code

<?php
$num=9;
$i=1;
while ($i<=10)
{
$total=$num*$i;
echo $num." * ".$i." = ".$total."<br>";
$i++;
}
?>

Output







MULTIPLICATION TABLE: Display Multiplication Table using Loop in PHP

MULTIPLICATION TABLE: Display Multiplication Table using Loop in PHP Rating: 4.5 Diposkan Oleh: Emoblazz

0 comments:

Post a Comment