Php make multiplication table, addition table (in Php learning)

Just pay attention to the addition on line 22.
If you don’t understand, the comments are raised, and I will answer within my ability.

<html>
<head>
    <title>算数表</title>
</head>
<body>
<?php
function a($a)
{
    echo'<table border="1">';
    for($i=9;$i>0;$i--)
    {
        echo'<tr>';
        for($j=$i;$j>0;$j--)
        {
            echo'<td>';
            if($a=="*")
            {
                echo $i."x".$j."=".$i*$j;
            }
            else if($a=="+")
            {
                echo $i."+".$j."=".($i+$j);//字符串的加法和变量的加法要用括号区别开
            }
            echo '</td>';
        }
        echo '</tr>';
    }
    echo    '</table>';
}
if(isset($_GET["sub"]))
{
    a($_GET["ra1"]);
}
?>
<form method="get" name="form1">
    <input type="radio" name="ra1" value="+">加法
    <br>
    <input type="radio" name="ra1" value="*">乘法
    <br>
    <input type="submit" name="sub">提交
</form>
</body>
</html>

Guess you like

Origin blog.csdn.net/qq_43228135/article/details/86775366