4
05/11/2024 8:03 am
Début du sujet
Hi, I want to create multiplication table in PHP - how can I do it? From 1 to 10
10x
2 Réponses
3
05/11/2024 8:05 am
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>

0
05/11/2024 8:05 am
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>
