belongs to collection: Loop PHP programs with examples
Write a PHP script using nested for loop that creates a chess board
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:
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
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.
Result:
need an explanation for this answer? contact us directly to get an explanation for this answer