How to write multiplication table in Php

王林
Release: 2023-02-26 17:52:01
Original
3617 people have browsed it

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 />";

}
Copy after login

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++;

}
Copy after login

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);
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template