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

Introduction

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.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. <html>
  2. <head>
  3. <title></title>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5. </head>
  6. <body>
  7.  
  8. <table width="300px" cellspacing="0px" cellpadding="0px" border="1px">
  9.  
  10. <?php
  11. for($row=1;$row<=8;$row++)
  12. {
  13. echo "<tr>";
  14. for($col=1;$col<=8;$col++)
  15. {
  16. $total=$row+$col;
  17. if($total%2==0)
  18. {
  19. echo "<td height=30px width=30px bgcolor=white></td>";
  20. }
  21. else
  22. {
  23. echo "<td height=30px width=30px bgcolor=black></td>";
  24. }
  25. }
  26. echo "</tr>";
  27. }
  28. ?>
  29. </table>
  30. </body>
  31. </html>

Result

python language techstudy.org

     





Related Topics




Popular Posts