Tablero de ajedrez


$tamany = 8;
echo "<table border=1>";
for ($i = 0; $i < $tamany; $i++) {
    echo "<tr>";
    for ($j = 0; $j < $tamany; $j++) {
        if (($i + $j) % 2 == 0) {
            echo "<td style='background-color:black;width:20px;height:20px'></td>";
        } else {
            echo "<td style='width:20px;height:20px'></td>";
        }
    }
    echo "</tr>";
}
echo "</table>";

Publicado por

Avatar del usuario

Juan Pablo Fuentes

Formador de programación y bases de datos