Write a program to create Chess board in PHP using for loop

Description:

Write a PHP program using nested for loop that creates a chess board.

Conditions:

  • You can use html table having width=”400px” and take “30px” as cell height and width for check boxes.

View Solution/Program

<table width="400px" cellspacing="0px" cellpadding="0px" border="1px">
<?php  
for($row=1;$row<=8;$row++)  
{  
	echo "<tr>";  
	for($column=1;$column<=8;$column++)  
	{
		$total=$row+$column;
		if($total%2==0)
		{  
			echo "<td height=35px width=30px bgcolor=#FFFFFF></td>";  
		}  
		else  
		{  
			echo "<td height=35px width=30px bgcolor=#000000></td>";  
		}  
	}  
	echo "</tr>";  
}  
?>  
</table>
Tutorials Class - Output Window

Chess-board-in-PHP-using-for-loop


Learn more about the similar topics:
Tutorials
PHP Loops
Exercises & Assignments
Write a program to count 5 to 15 using PHP loop
Write a factorial program using for loop in php
Factorial program in PHP using recursive function
Write a program to create Chess board in PHP using for loop
Write a Program to create given pattern with * using for loop
Interview Questions & Answers
No Content Found.