Simulate betting in PHP

2

I want to make a PHP script that completes the realization of a random pool. I have the following code, which would make a simple table of 15 rows and 3 columns. I do not know how to randomly mark in each row a 1, X or 2. I tried a rand (1,3), if and so on but did not manage to put it in its correct place so that the result is put in its column correspondent. That is, if 1 comes out, it is placed in column 1 of that row. Can someone help me?

<?php
echo "<table border='1'>";
 for ($fila=1; $fila<16; $fila++){
  echo "<tr>";
  for ($col=1; $col<4; $col++){
   echo "<td align='center'>";
 }
}

If possible, do not use arrays, just if, switch, loops or functions.

    
asked by Norad 28.10.2016 в 20:01
source

1 answer

1

View Demo

<?php

echo "<table border='1'>";

// creas el array con los marcadores
$marca = ["1", "x", "2"];

for ($i = 0; $i < 15; $i++) {

    // elegir resultado con rand()
    $res = $marca[rand(0,2)];

    echo "<tr>";

    // con switch ordenas cada fila del resultado $res
    switch ($res) {

        case "1":
            echo "<td>1</td><td>-</td><td>-</td>";
            break;

        case "x":
            echo "<td>-</td><td>x</td><td>-</td>";
            break;

        case "2":
            echo "<td>-</td><td>-</td><td>2</td>";
            break;
    }

    echo "</tr>";
}

echo "</table>";
    
answered by 28.10.2016 / 20:37
source