Q:

Write a PHP script using nested for loop that creates a chess board

belongs to collection: Loop PHP programs with examples

0

Write a PHP script using nested for loop that creates a chess board

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

PHP is a server scripting language, and It is a powerful tool for making interactive and dynamic Web-pages. I have used WampServer 2.2 for following example.

<html> 
     <head> 
  <title></title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body> 
 
   <table width="300px" cellspacing="0px" cellpadding="0px" border="1px">
 
      <?php
      for($row=1;$row<=8;$row++)
      {
          echo "<tr>";
          for($col=1;$col<=8;$col++)
          {
          $total=$row+$col;
          if($total%2==0)
          {
          echo "<td height=30px width=30px bgcolor=white></td>";
          }
          else
          {
          echo "<td height=30px width=30px bgcolor=black></td>";
          }
          }
          echo "</tr>";
    }
          ?>
  </table>
  </body>
  </html>

Result:

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Write a PHP script to print all even numbers betwe... >>
<< Write a program which will count the “t” chara...