SoFunction
Updated on 2025-03-09

Share a PHP definition function code

Post the code first

Copy the codeThe code is as follows:

<?php
    function table(){
        echo "<table align='center' border='1' width='600' cellspacing='0';>";
echo "<caption><h1>This is the title of the table</h1></caption>";
        for($out=0; $out < 10; $out++ ){
            $bgcolor = $out%2 == 0 ? "#ffffff" : "green";
            $fontcolor = $out%2 == 0 ? "#ffffff" : "#000000";
            echo "<tr bgcolor=".$bgcolor.">";
            for($in=0;$in<10;$in++){
                echo "<td>".($out*10+$in)."</td>";
            };
            echo "</tr>";
        };
        echo "</table>";
    }
    table();
?>

This is a piece of code that defines functions

tips:

1. Pay attention to the syntax format of PHP

2. Pay attention to the way of inserting Html code in PHP

3. When using for loops, pay attention to the difference between the external loop and the inner loop.