Home >Backend Development >PHP Problem >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!