创建下表的PHP脚本(用于循环)

时间:2016-07-15 12:57:34

标签: php logic

在我的一个项目中,我希望拥有一定数量的图案,如图中所示但是它的小点,任何帮助都将受到赞赏

<?php  
    echo "<table border =\"1\" style='border-collapse: collapse'>";  
    for ($row=1; $row <= 10; $row++) {   
        echo "<tr> \n";  
        for ($col=1; $col <= 10; $col++) {   
            $p = $col+1 * $row+1;  
            echo "<td>$p</td> \n";  
        }  
        echo "</tr>";  
    }  
    echo "</table>";  
?>  

enter image description here

预期输出

enter image description here

6 个答案:

答案 0 :(得分:1)

试试这个:

<?php  
    echo "<table border =\"1\" style='border-collapse: collapse'>";  
    for ($row=1; $row <= 10; $row++) {   
        echo "<tr> \n";  
        for ($col = 1; $col <= 10; $col++) {  
            echo "<td>" . $col * $row . "</td> \n";  
        }  
        echo "</tr>";  
    }  
    echo "</table>";  
?>

答案 1 :(得分:1)

echo "<table>";

for ($i = 1; $i <= 10; $i++) {
    echo "<tr>";

    $temp = $i;
    for ($m = 1; $m <= 10; $m++) {
        echo "<td>" . $temp . "</td>";
        $temp += $i;
    }

    echo "<tr>";
}

echo "</table>";

答案 2 :(得分:1)

试试这个, 删除$ col和$ row

中的增量
echo "<table border ='1' style='border-collapse: collapse'>";  
for ($row=1; $row <= 10; $row++) {   
    echo "<tr> \n";  
    for ($col=1; $col <= 10; $col++) {   
        $p = $col * $row;  
        echo "<td>$p</td> \n";  
    }  
    echo "</tr>";  
}  
echo "</table>";

我希望它会有所帮助。

答案 3 :(得分:0)

试试这段代码......

<?php  
    echo "<table border =\"1\" style='border-collapse: collapse'>";  
    for ($row=1; $row <= 10; $row++)
    {
        echo "<tr> \n";  
        for ($col=1; $col <= 10; $col++)
        {
           $p = $col * $row;
           echo "<td>$p</td> \n";  
        }  
        echo "</tr>";  
    }  
    echo "</table>";  
    ?> 

答案 4 :(得分:0)

<?php
echo"Ashutosh Verma Branch_IT_9889313834";
echo"<br />";
echo "-------The table of 5-------";
echo"<br/>";
$s=5;
for($i=1; $i<=10; $i++)
{
$t = $i*$s;
echo $s."*".$i."=".$t."<br/>";
}
?>
------------Output Section-------
Ashutosh Verma Branch_IT_9889313834
-------The table of 5-------
5*1=5
5*2=10
5*3=15
5*4=20
5*5=25
5*6=30
5*7=35
5*8=40
5*9=45
5*10=50

答案 5 :(得分:0)

enter code here<?php  
echo "<table border =\"1\" style='border-collapse: collapse'>";  
for ($row=1; $row <= 10; $row++) {   
    echo "<tr> \n";  
    for ($col=1; $col <= 10; $col++) {   
        $p = $col+1 * $row+1;  
        echo "<td>$p</td> \n";  
    }  
    echo "</tr>";  
}  
echo "</table>";  

?>