Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //the array
- $table = array();
- //if the users picks numbers grab from form
- if (isset($_POST["coords"])) {
- $td1 = $_POST["td1"];
- $td2 = $_POST["td2"];
- //if not generate two randoms
- } else {
- $td1 = rand(1, 10);
- $td2 = rand(1, 10);
- }
- echo $td1 . " " . $td2;
- //generate a 2 dimensional array
- for ($i = 0; $i <= 10; $i++) {
- for ($n = 0; $n <= 10; $n++) {
- //find a 'O' or 'X'
- $rand = rand(0, 1);
- //make a cell red
- if ($i == $td1 && $n == $td2) {
- if ($rand == 0) {
- $table[$i][$n] = "<span style='background:red;'> X </span>";
- } else {
- $table[$i][$n] = "<span style='background:red;'>O</span>";
- }
- }
- //make the rest defaults
- elseif ($rand == 0) {
- $table[$i][$n] = "X";
- } else {
- $table[$i][$n] = "O";
- }
- }
- }
- //print the arrays
- echo "<pre>";
- //print_r($table);
- echo "</pre>";
- //shuffle the array
- //start the table
- echo "<table style='float:left; margin-right:20px;' border='1'>";
- echo "<tr>";
- echo "<td></td>";
- for ($td = 0; $td <= 10; $td++) {
- echo "<td>$td</td>";
- }
- echo "</tr>";
- //echo the tables
- foreach ($table as $row => $col) {
- echo "<tr><td>$row</td>";
- foreach ($col as $cell) {
- echo "<td>$cell</td>";
- }
- echo '</tr>';
- }
- echo "</table>";
- ?>
- Pick the red field
- <form action="" method="POST">
- <input type="number" value="<?php echo $_POST["td1"]; ?>" name="td1" style="width:50px;"/>
- x
- <input type="number" value="<?php echo $_POST["td2"]; ?>" name="td2" style="width:50px;"/>
- <input type="submit" value="Pick it!" name="coords" />
- </form>
Add Comment
Please, Sign In to add comment