Home >Backend Development >PHP Problem >How to write 10 rows and 10 columns using for loop in PHP

How to write 10 rows and 10 columns using for loop in PHP

藏色散人
藏色散人Original
2019-09-28 16:46:426067browse

How to write 10 rows and 10 columns using for loop in PHP

How to write 10 rows and 10 columns using a for loop in php?

php uses a for loop to implement a table with 10 rows and 10 columns:

The code is like:

<?php
echo "<table border =\"1\" style=&#39;border-collapse: collapse&#39;>";
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>";
?>

The output result is like:

How to write 10 rows and 10 columns using for loop in PHP

Note: PHP for loop executes the code block a specified number of times.

For more PHP knowledge, please visit PHP Chinese website!

The above is the detailed content of How to write 10 rows and 10 columns using for loop 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