settingsAccountsettings
By using our mini forum, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy
Menusettings

Q: Multiplication table in PHP - Please help create

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

10x
asked in PHP category by user matthew44

2 Answers

+4 votes
 
Best answer

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

answered by user hues
selected by user golearnweb
+4 votes

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>
answered by user richard8502
edited by user golearnweb
...