Write a program to print a chess board in php

In this article, We’ll write a program to print a chess board in php.




echo "
<table style='border:1px solid #ddd'>";
$k = 0;
for ($i = 1; $i <= 8; $i++) {
     echo "
<tr>";
     for ($j = 1; $j <= 8; $j++) {
             $clr = $k % 2 ? '#000' : '#fff';
             $style = "style='background:$clr;width:20px;height:20px'";
             echo "
<td $style></td>

";
             $k++;
     }
     $k++;
     echo "</tr>

";
}
     echo "</table>

";

Output:

Chess Board

That’s it!. Please share your thoughts or suggestions in the comments below.

Leave a Reply

Your email address will not be published. Required fields are marked *