Home >Backend Development >PHP Problem >How to write multiplication table in Php

How to write multiplication table in Php

王林
王林Original
2019-10-15 13:14:253669browse

How to write multiplication table in Php

How to write a multiplication table in PHP

1. Use a for loop to print the multiplication table

<?php

for($j=1; $j<=9; $j++) {

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

echo "{$i}x{$j}=".($i*$j)." ";

}
echo "<br />";

}

2. Use a while loop to print the multiplication table

<?php
$j = 1;

while($j<=9){

$i = 1;

while($i<=$j){

echo "{$i}x{$j}=".($i*$j)." ";

$i++;

}

echo "<br />";

$j++;

}

3. Use a do while loop to print the multiplication table

<?php

$j = 1;

do {

$i = 1;

do {

echo "{$i}x{$j}=".($i*$j)." ";

$i++;

} while($i<=$j);

echo "<br />";

$j++;

} while($j<=9);

Recommended tutorial: PHP video tutorial

The above is the detailed content of How to write multiplication table in Php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn