0

I have a table of 6 by 6, and Im trying to set 6 elements inside that table that cannot cross each other (think of chess). Im terrible with math and these thing to not sure if there's an easy way to build something?

In my example below the variables totalElements & $match do nothing but should set 6 elements.

        $size = 6;
        $totalElements = 6
        echo '<table>';
        for ($i = 1; $i <= $size; $i++) {
            echo '<tr>';
            for ($ii = 1; $ii <= $size; $ii++) {
                echo '<td>';
                // $match should set an element
                // this element can not be crossed vertical, 
                // horizontal or diagonal
                // $totalElements = number of elements that must be set
                if($match && $totalElements){
                    echo '<div>X</div>';
                }
                echo '</td>';
            }
            echo '</tr>';
        }
        echo '</table>';
user759235
  • 2,147
  • 3
  • 39
  • 77

1 Answers1

0

if you want to create chess board game or something like this. you can follow this code

 echo '<table>';
        for($row=1;$row<=6;$row++)
        {
            echo "<tr>";
            for($col=1;$col<=6;$col++)
            {
                $total=$row+$col;
                if($total%2==0){
                echo "<td style='background:blue'>X</td>";
                }else{
                echo "<td style='background:red'>Y</td>";
                }
            }
            echo "</tr>";
      }
        echo '</table>';
mohammad13
  • 453
  • 3
  • 17