[Solved] Multiplication table in PHP - Please help create

  

4
Topic starter

Hi, I want to create multiplication table in PHP - how can I do it? From 1 to 10

10x

2 Answers
3

Here's mine...In line #19 I've used concatanation, instead of $result variable creation.

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Multiplication Table in Php</title>
</head>
<body>
 
<?php
 
$x = 1; //rows
echo "<table border = '2'>\n";
 
while ( $x <= 10 ) {
    echo "\t<tr>\n";
 
    $y = 1;//columns
    while ( $y <= 10 ) {
        echo "\t\t<td>$x * $y = " . $x * $y . "</td>\n";//the result of the multiplication
        $y++;
    }
 
    echo "\t</tr>\n";
    $x++;
}
 
echo "</table>";
 
?>
 
</body>
</html>

multiplication table in php

0

Here is my solution:

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>PHP Multiplication Table</title>
</head>
<body>
 
<?php
 
$i = 1;
echo "<table border='1'>\n";
while ( $i <= 10 ) {
    echo "\t<tr>\n";
    $n = 1;
    while ( $n <= 10 ) {
        $result = $n * $i;
        echo "\t\t<td>$n * $i =  $result</td>\n";
        $n++;
    }
    echo "\t</tr>\n";
    $i++;
}
 
?>
 
</body>
</html>
Share: