Ejercicios (con formularios) - Selección (1) - Soluciones

En esta página se muestran una parte de las soluciones de los ejercicios Selección (1), concretamente el fragmento PHP, sin el principio ni el final de la página que se pueden dejar en fragmentos HTML.

Si lo prefiere, puede descargar unas posibles soluciones completas de estos ejercicios.

Selección (1) 1 - Su cambio

<?php
// Función de recogida de datos
function recoge($key, $type = "")
{
    if (!is_string($key) && !is_int($key) || $key == "") {
        trigger_error("Function recoge(): Argument #1 (\$key) must be a non-empty string or an integer", E_USER_ERROR);
    } elseif ($type !== "" && $type !== []) {
        trigger_error("Function recoge(): Argument #2 (\$type) is optional, but if provided, it must be an empty array or an empty string", E_USER_ERROR);
    }
    $tmp = $type;
    if (isset($_REQUEST[$key])) {
        if (!is_array($_REQUEST[$key]) && !is_array($type)) {
            $tmp = trim(htmlspecialchars($_REQUEST[$key]));
        } elseif (is_array($_REQUEST[$key]) && is_array($type)) {
            $tmp = $_REQUEST[$key];
            array_walk_recursive($tmp, function (&$value) {
                $value = trim(htmlspecialchars($value));
            });
        }
    }
    return $tmp;
}

$deuda = recoge("deuda");
$b200  = recoge("b200");
$b100  = recoge("b100");

$deudaOk = false;
$b200Ok  = false;
$b100Ok  = false;

if ($deuda == "") {
    print "  <p class=\"aviso\">No ha escrito la cantidad a pagar.</p>\n";
    print "\n";
} elseif (!is_numeric($deuda)) {
    print "  <p class=\"aviso\">No ha escrito la cantidad a pagar como número.</p>\n";
    print "\n";
} elseif (!ctype_digit($deuda)) {
    print "  <p class=\"aviso\">No ha escrito la cantidad a pagar como número entero.</p>\n";
    print "\n";
} elseif ($deuda % 100 != 0) {
    print "  <p class=\"aviso\">La cantidad no es un múltiplo de cien.</p>\n";
    print "\n";
} else {
    $deudaOk = true;
}

if ($b200 == "") {
    print "  <p class=\"aviso\">No ha escrito el número de billetes de doscientos.</p>\n";
    print "\n";
} elseif (!is_numeric($b200)) {
    print "  <p class=\"aviso\">No ha escrito el número de billetes de doscientos como número.</p>\n";
    print "\n";
} elseif (!ctype_digit($b200)) {
    print "  <p class=\"aviso\">No ha escrito el número de billetes de doscientos como número entero.</p>\n";
    print "\n";
} else {
    $b200Ok = true;
}

if ($b100 != 0 && $b100 != 1 && $b100 != 2 && $b100 != 3) {
    print "  <p class=\"aviso\">El número de billetes de cien no es correcto.</p>\n";
    print "\n";
} else {
    $b100Ok = true;
}

if ($deudaOk && $b200Ok && $b100Ok) {
    $pagado = 200 * $b200 + 100 * $b100;
    print "  <p>Tiene que pagar <strong>$deuda €</strong>.</p>\n";
    print "\n";
    print "  <p>Ha entregado <strong>$pagado €</strong>.</p>\n";
    print "\n";

    if ($pagado == $deuda) {
        print "  <p>Ha entregado la cantidad exacta.</p>\n";
        print "\n";
    } elseif ($pagado < $deuda) {
        print "  <p>Le falta entregar <strong>" . ($deuda - $pagado) . " €</strong>.</p>\n";
        print "\n";
    } else {
        $cambio = $pagado - $deuda;
        $c200   = floor($cambio / 200);
        $c100   = $cambio % 200 / 100;
        print "  <p>Tome su cambio: <strong>$cambio €</strong> (<strong>$c200</strong> billetes de 200 € y <strong>$c100</strong> de 100 €).</p>\n";
        print "\n";
    }
}
?>

Selección (1) 2 - Camisetas

<?php
// Función de recogida de datos
function recoge($key, $type = "")
{
    if (!is_string($key) && !is_int($key) || $key == "") {
        trigger_error("Function recoge(): Argument #1 (\$key) must be a non-empty string or an integer", E_USER_ERROR);
    } elseif ($type !== "" && $type !== []) {
        trigger_error("Function recoge(): Argument #2 (\$type) is optional, but if provided, it must be an empty array or an empty string", E_USER_ERROR);
    }
    $tmp = $type;
    if (isset($_REQUEST[$key])) {
        if (!is_array($_REQUEST[$key]) && !is_array($type)) {
            $tmp = trim(htmlspecialchars($_REQUEST[$key]));
        } elseif (is_array($_REQUEST[$key]) && is_array($type)) {
            $tmp = $_REQUEST[$key];
            array_walk_recursive($tmp, function (&$value) {
                $value = trim(htmlspecialchars($value));
            });
        }
    }
    return $tmp;
}

$color  = recoge("color");
$genero = recoge("genero");
$texto  = recoge("texto");

$colorOk  = false;
$generoOk = false;
$textoOk  = false;

if ($color == "") {
    print "  <p class=\"aviso\">No ha escrito ningún color.</p>\n";
    print "\n";
} else {
    $colorOk = true;
}

if ($genero != "h" && $genero != "m") {
    print "  <p class=\"aviso\">Debe elegir un sexo: hombre o mujer.</p>\n";
    print "\n";
} else {
    $generoOk = true;
}

if ($texto == "") {
    print "  <p class=\"aviso\">No ha escrito ningún texto.</p>\n";
    print "\n";
} elseif (strlen($texto) > 9) {
    print "  <p class=\"aviso\">El texto es demasiado largo.</p>\n";
    print "\n";
} else {
    $textoOk = true;
}

if ($colorOk && $generoOk && $textoOk) {
    if ($genero == "m") {
        print "  <p>\n";
        print "    <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"244\" height=\"328\" viewBox=\"0 0 121.793 163.392\">\n";
        print "      <g>\n";
        print "        <path fill=\"$color\" stroke=\"black\" fill-rule=\"evenodd\" d=\"M41.14 0s-14.1 4.16-20.57 6.7C14.1 9.24 5.32 15.7 3
            20.1c-2.3 4.4-3 6.5-3 6.5s4.62 3 8.78 9.24c4.16 6.24 11.56 10.4 11.56 10.4s.15 16.9 5.3 28.9c7 16.2-.9 35.8-4.38
            45.75-3.47 9.9-6 42.5-6 42.5h94.05s-1.32-24.77-7.6-40c-6.2-15.27-9.7-36.77-4.4-47.86 5.3-11.1 4.9-29.12 4.9-29.12s6.7-3.7
            9-8.1c2.3-4.38 5.8-7.6 7.4-9.7 1.6-2.07 3.24-2.3 3.24-2.3s-4.16-8.8-6.24-11.56c-2.1-2.8-8.1-5.33-14.1-8.1C95.45 3.92 80.9
            0 80.9 0s-5.56 3.7-18.04 3.7S41.14 0 41.14 0z\" clip-rule=\"evenodd\"/>\n";
        print "      </g>\n";
        print "      <defs><path id=\"camino\" d=\"M20 40 Q 60 70 100 40\" /></defs>\n";
        //        print "      <use xlink:href=\"#camino\" fill=\"none\" stroke=\"red\" />\n";
        print "      <text font-family=\"sans-serif\" font-size=\"20\"><textPath xlink:href=\"#camino\">$texto</textPath></text>\n";
        print "    </svg>\n";
        print "  </p>\n";
        print "\n";
    } else {
        print "  <p>\n";
        print "    <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"266\" height=\"332\" viewBox=\"0 0 138.37401 171.27\">\n";
        print "      <g>\n";
        print "        <path fill=\"$color\" stroke=\"black\" fill-rule=\"evenodd\" d=\"M48.72.25s-24.6 12.56-30.4 15.82C12.57 19.34 8.3 23.35 6.3 32.9
            4.28 42.44 0 72.83 0 72.83s13.3 4.52 18.83 4.52c5.53 0 8.8-1.5 8.8-1.5l.24 95.42H113v-99.2s6.3 1.26 11.56.5c5.28-.75 13.8-5.27
            13.8-5.27s-7.77-35.9-9.03-42.94c-1.25-7.03-8.28-10.55-15.82-13.3C106 8.28 89.4 0 89.4 0s-5.02 4.52-17.57 5.02c-12.56.5-23.1-4.77-23.1-4.77z\"
            clip-rule=\"evenodd\"/>\n";
        print "      </g>\n";
        print "      <defs><path id=\"camino\" d=\"M20 50 Q 70 80 120 50\" /></defs>\n";
        //        print "      <use xlink:href=\"#camino\" fill=\"none\" stroke=\"red\" />\n";
        print "      <text font-family=\"sans-serif\" font-size=\"22\"><textPath xlink:href=\"#camino\">$texto</textPath></text>\n";
        print "    </svg>\n";
        print "  </p>\n";
        print "\n";
    }
}
?>

Selección (1) 3 - Puntos en cuadrantes

<?php
// Función de recogida de datos
function recoge($key, $type = "")
{
    if (!is_string($key) && !is_int($key) || $key == "") {
        trigger_error("Function recoge(): Argument #1 (\$key) must be a non-empty string or an integer", E_USER_ERROR);
    } elseif ($type !== "" && $type !== []) {
        trigger_error("Function recoge(): Argument #2 (\$type) is optional, but if provided, it must be an empty array or an empty string", E_USER_ERROR);
    }
    $tmp = $type;
    if (isset($_REQUEST[$key])) {
        if (!is_array($_REQUEST[$key]) && !is_array($type)) {
            $tmp = trim(htmlspecialchars($_REQUEST[$key]));
        } elseif (is_array($_REQUEST[$key]) && is_array($type)) {
            $tmp = $_REQUEST[$key];
            array_walk_recursive($tmp, function (&$value) {
                $value = trim(htmlspecialchars($value));
            });
        }
    }
    return $tmp;
}

$cantidad  = recoge("cantidad");
$cuadrante = recoge("cuadrante");

$cantidadOk  = false;
$cuadranteOk = false;

if ($cantidad == "") {
    print "  <p class=\"aviso\">No ha escrito el número de puntos.</p>\n";
    print "\n";
} elseif (!is_numeric($cantidad)) {
    print "  <p class=\"aviso\">No ha escrito el número de puntos como número.</p>\n";
    print "\n";
} elseif (!ctype_digit($cantidad)) {
    print "  <p class=\"aviso\">No ha escrito el número de puntos como número entero.</p>\n";
    print "\n";
} elseif ($cantidad < 3 || $cantidad > 12) {
    print "  <p class=\"aviso\">El número de puntos solicitado no está en el rango permitido.</p>\n";
    print "\n";
} else {
    $cantidadOk = true;
}

if ($cuadrante != "Arriba a la derecha" && $cuadrante != "Abajo a la derecha"
        && $cuadrante != "Abajo a la izquierda" && $cuadrante != "Arriba a la izquierda") {
    print "  <p class=\"aviso\">El cuadrante solicitado no es uno de los permitidos.</p>\n";
    print "\n";
} else {
    $cuadranteOk = true;
}

if ($cantidadOk && $cuadranteOk) {
    print "  <p>\n";
    print "    <svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\"\n";
    print "         width=\"400\" height=\"400\" viewBox=\"-200 -200 400 400\"\n";
    print "      style=\"border: black 1px solid\" >\n";
    print "      <line x1=\"0\" y1=\"-200\" x2=\"0\" y2=\"200\" stroke-width=\"1\" stroke=\"blue\" />\n";
    print "      <line x1=\"-200\" y1=\"0\" x2=\"200\" y2=\"0\" stroke-width=\"1\" stroke=\"blue\" />\n";
    $hayPuntos = false;
    for ($i = 0; $i < $cantidad; $i++) {
        $px = rand(-200, 200);
        $py = rand(-200, 200);
        print "      <circle cx=\"$px\" cy=\"$py\" r=\"2\" fill=\"red\" />\n";
        if ($cuadrante == "Arriba a la derecha" && $px >= 0 && $py <= 0) {
            $hayPuntos = true;
        } elseif ($cuadrante == "Abajo a la derecha" && $px >= 0 && $py >= 0) {
            $hayPuntos = true;
        } elseif ($cuadrante == "Abajo a la izquierda" && $px <= 0 && $py >= 0) {
            $hayPuntos = true;
        } elseif ($cuadrante == "Arriba a la izquierda" && $px <= 0 && $py <= 0) {
            $hayPuntos = true;
        }
    }
    print "    </svg>\n";
    print "  </p>\n";
    print "\n";

    if ($hayPuntos) {
        print "  <p>Hay puntos $cuadrante.</p>\n";
    } else {
        print "  <p>No hay puntos $cuadrante.</p>\n";
    }
}
?>

Selección (1) 4 - Comparador de tres números

<?php
// Función de recogida de datos
function recoge($key, $type = "")
{
    if (!is_string($key) && !is_int($key) || $key == "") {
        trigger_error("Function recoge(): Argument #1 (\$key) must be a non-empty string or an integer", E_USER_ERROR);
    } elseif ($type !== "" && $type !== []) {
        trigger_error("Function recoge(): Argument #2 (\$type) is optional, but if provided, it must be an empty array or an empty string", E_USER_ERROR);
    }
    $tmp = $type;
    if (isset($_REQUEST[$key])) {
        if (!is_array($_REQUEST[$key]) && !is_array($type)) {
            $tmp = trim(htmlspecialchars($_REQUEST[$key]));
        } elseif (is_array($_REQUEST[$key]) && is_array($type)) {
            $tmp = $_REQUEST[$key];
            array_walk_recursive($tmp, function (&$value) {
                $value = trim(htmlspecialchars($value));
            });
        }
    }
    return $tmp;
}

$numero1 = recoge("numero1");
$numero2 = recoge("numero2");
$numero3 = recoge("numero3");

$numero1Ok = false;
$numero2Ok = false;
$numero3Ok = false;

if ($numero1 == "") {
    print "  <p class=\"aviso\">No ha escrito el primer número.</p>\n";
    print "\n";
} elseif (!is_numeric($numero1)) {
    print "  <p class=\"aviso\">No ha escrito el primer número como número.</p>\n";
    print "\n";
} elseif ($numero1 <= -1000 || $numero1 >= 1000) {
    print "  <p class=\"aviso\">El primer número no está entre -1.000 y 1.000.</p>\n";
    print "\n";
} else {
    $numero1Ok = true;
}

if ($numero2 == "") {
    print "  <p class=\"aviso\">No ha escrito el segundo numero.</p>\n";
    print "\n";
} elseif (!is_numeric($numero2)) {
    print "  <p class=\"aviso\">No ha escrito el segundo número como número.</p>\n";
    print "\n";
} elseif ($numero2 <= -1000 || $numero2 >= 1000) {
    print "  <p class=\"aviso\">El segundo número no está entre -1.000 y 1.000.</p>\n";
    print "\n";
} else {
    $numero2Ok = true;
}

if ($numero3 == "") {
    print "  <p class=\"aviso\">No ha escrito el tercer numero.</p>\n";
    print "\n";
} elseif (!is_numeric($numero3)) {
    print "  <p class=\"aviso\">No ha escrito el tercer número como número.</p>\n";
    print "\n";
} elseif ($numero3 <= -1000 || $numero3 >= 1000) {
    print "  <p class=\"aviso\">El tercer número no está entre -1.000 y 1.000.</p>\n";
    print "\n";
} else {
    $numero3Ok = true;
}

if ($numero1Ok && $numero2Ok && $numero3Ok) {
    print "  <p>Primer número: <strong>$numero1</strong></p>\n";
    print "\n";
    print "  <p>Segundo número: <strong>$numero2</strong></p>\n";
    print "\n";
    print "  <p>Tercer número: <strong>$numero3</strong></p>\n";
    print "\n";
    if ($numero1 == $numero2 && $numero2 == $numero3) {
        print "  <p>Ha escrito tres números iguales.</p>\n";
    } elseif ($numero1 == $numero2 || $numero2 == $numero3 || $numero1 == $numero3) {
        print "  <p>Ha escrito dos números iguales.</p>\n";
    } else {
        print "  <p>Ha escrito tres números distintos.</p>\n";
    }
    print "\n";
}
?>

Selección (1) 5 - Convertidor de temperaturas Celsius / Fahrenheit

<?php
// Función de recogida de datos
function recoge($key, $type = "")
{
    if (!is_string($key) && !is_int($key) || $key == "") {
        trigger_error("Function recoge(): Argument #1 (\$key) must be a non-empty string or an integer", E_USER_ERROR);
    } elseif ($type !== "" && $type !== []) {
        trigger_error("Function recoge(): Argument #2 (\$type) is optional, but if provided, it must be an empty array or an empty string", E_USER_ERROR);
    }
    $tmp = $type;
    if (isset($_REQUEST[$key])) {
        if (!is_array($_REQUEST[$key]) && !is_array($type)) {
            $tmp = trim(htmlspecialchars($_REQUEST[$key]));
        } elseif (is_array($_REQUEST[$key]) && is_array($type)) {
            $tmp = $_REQUEST[$key];
            array_walk_recursive($tmp, function (&$value) {
                $value = trim(htmlspecialchars($value));
            });
        }
    }
    return $tmp;
}

$temperatura = recoge("temperatura");
$unidad      = recoge("unidad");

$temperaturaOk = false;
$unidadOk      = false;

if ($temperatura == "") {
    print "  <p class=\"aviso\">No ha escrito la temperatura.</p>\n";
    print "\n";
} elseif (!is_numeric($temperatura)) {
    print "  <p class=\"aviso\">No ha escrito la temperatura como número.</p>\n";
    print "\n";
} elseif ($temperatura < -273.15 && $unidad == "c") {
    print "  <p class=\"aviso\">Una temperatura no puede ser tan baja.</p>\n";
    print "\n";
} elseif ($temperatura < -459.67 && $unidad == "f") {
    print "  <p class=\"aviso\">Una temperatura no puede ser tan baja.</p>\n";
    print "\n";
} elseif ($temperatura >= 10000) {
    print "  <p class=\"aviso\">La temperatura no es inferior a 10.000.</p>\n";
    print "\n";
} else {
    $temperaturaOk = true;
}

if ($unidad != "c" && $unidad != "f") {
    print "  <p class=\"aviso\">La unidad no es correcta.</p>\n";
    print "\n";
} else {
    $unidadOk = true;
}

if ($temperaturaOk && $unidadOk) {
    if ($unidad == "c") {
        $fahrenheit = round(1.8 * $temperatura + 32, 2);
        print "  <p>$temperatura ºC son $fahrenheit ºF</p>\n";
    } else {
        $celsius = round(($temperatura - 32) / 1.8, 2);
        print "  <p>$temperatura ºF son $celsius ºC</p>\n";
    }
    print "\n";
}
?>

Selección (1) 6 - Cuenta palos

<?php
// Función de recogida de datos
function recoge($key, $type = "")
{
    if (!is_string($key) && !is_int($key) || $key == "") {
        trigger_error("Function recoge(): Argument #1 (\$key) must be a non-empty string or an integer", E_USER_ERROR);
    } elseif ($type !== "" && $type !== []) {
        trigger_error("Function recoge(): Argument #2 (\$type) is optional, but if provided, it must be an empty array or an empty string", E_USER_ERROR);
    }
    $tmp = $type;
    if (isset($_REQUEST[$key])) {
        if (!is_array($_REQUEST[$key]) && !is_array($type)) {
            $tmp = trim(htmlspecialchars($_REQUEST[$key]));
        } elseif (is_array($_REQUEST[$key]) && is_array($type)) {
            $tmp = $_REQUEST[$key];
            array_walk_recursive($tmp, function (&$value) {
                $value = trim(htmlspecialchars($value));
            });
        }
    }
    return $tmp;
}

$cantidad = recoge("cantidad");
$palo1    = recoge("palo1");
$palo2    = recoge("palo2");

$cantidadOk = false;
$palo1Ok    = false;
$palo2Ok    = false;

if ($cantidad == "") {
    print "  <p class=\"aviso\">No ha escrito el número de cartas.</p>\n";
    print "\n";
} elseif (!is_numeric($cantidad)) {
    print "  <p class=\"aviso\">No ha escrito el número de cartas como número.</p>\n";
    print "\n";
} elseif (!ctype_digit($cantidad)) {
    print "  <p class=\"aviso\">No ha escrito el número de cartas como número entero.</p>\n";
    print "\n";
} elseif ($cantidad < 3 || $cantidad > 7) {
    print "  <p class=\"aviso\">El número de cartas indicado no está en el rango permitido.</p>\n";
    print "\n";
} else {
    $cantidadOk = true;
}

if ($palo1 == "") {
    print "  <p class=\"aviso\">No ha elegido el primer palo.</p>\n";
    print "\n";
} elseif ($palo1 != "c" && $palo1 != "d" && $palo1 != "p" && $palo1 != "t") {
    print "  <p class=\"aviso\">El primer palo indicado no es uno de los permitidos.</p>\n";
    print "\n";
} else {
    $palo1Ok = true;
}

if ($palo2 == "") {
    print "  <p class=\"aviso\">No ha elegido el segundo palo.</p>\n";
    print "\n";
} elseif ($palo2 != "c" && $palo2 != "d" && $palo2 != "p" && $palo2 != "t") {
    print "  <p class=\"aviso\">El segundo palo indicado no es uno de los permitidos.</p>\n";
    print "\n";
} else {
    $palo2Ok = true;
}

if ($palo1 == $palo2 && $palo1 != "") {
    print "  <p class=\"aviso\">Los palos deben ser distintos.</p>\n";
    print "\n";
    $palo1Ok = $palo2Ok = false;
}

if ($cantidadOk && $palo1Ok && $palo2Ok) {
    $tiposPalos   = ["c", "d", "p", "t"];
    $nombresPalos = ["c" => "corazones", "d" => "diamantes", "p" => "picas", "t" => "tréboles"];
    $cartas       = [];
    $palos        = [];
    $cuenta1      = 0;
    $cuenta2      = 0;
    for ($i = 0; $i < $cantidad; $i++) {
        $cartas[$i] = rand(1, 10);
        $palos[$i]  = $tiposPalos[rand(0, 3)];
        if ($palos[$i] == $palo1) {
            $cuenta1 += 1;
        } elseif ($palos[$i] == $palo2) {
            $cuenta2 += 1;
        }
    }

    print "  <h2>$cantidad cartas";
    print "</h2>\n";
    print "\n";

    print "  <p>\n";
    for ($i = 0; $i < $cantidad; $i++) {
        print "    <img src=\"img/$palos[$i]$cartas[$i].svg\" alt=\"$cartas[$i]\" width=\"100\">\n";
    }
    print "  </p>\n";
    print "\n";

    print "  <h2>Resultado</h2>\n";
    print "\n";
    print "  <p>Hay {$cuenta1} cartas de {$nombresPalos[$palo1]} y {$cuenta2} cartas de {$nombresPalos[$palo2]}.</p>\n";
    print "\n";
}
?>

Selección (1) 7 - Reparto de tríos

<?php
// Función de recogida de datos
function recoge($key, $type = "")
{
    if (!is_string($key) && !is_int($key) || $key == "") {
        trigger_error("Function recoge(): Argument #1 (\$key) must be a non-empty string or an integer", E_USER_ERROR);
    } elseif ($type !== "" && $type !== []) {
        trigger_error("Function recoge(): Argument #2 (\$type) is optional, but if provided, it must be an empty array or an empty string", E_USER_ERROR);
    }
    $tmp = $type;
    if (isset($_REQUEST[$key])) {
        if (!is_array($_REQUEST[$key]) && !is_array($type)) {
            $tmp = trim(htmlspecialchars($_REQUEST[$key]));
        } elseif (is_array($_REQUEST[$key]) && is_array($type)) {
            $tmp = $_REQUEST[$key];
            array_walk_recursive($tmp, function (&$value) {
                $value = trim(htmlspecialchars($value));
            });
        }
    }
    return $tmp;
}

$jugadores = recoge("jugadores");

$jugadoresOk = false;

if ($jugadores == "") {
    print "  <p class=\"aviso\">No ha escrito el número de jugadores.</p>\n";
    print "\n";
} elseif (!is_numeric($jugadores)) {
    print "  <p class=\"aviso\">No ha escrito el número de jugadores como número.</p>\n";
    print "\n";
} elseif (!ctype_digit($jugadores)) {
    print "  <p class=\"aviso\">No ha escrito el número de jugadores como número entero positivo.</p>\n";
    print "\n";
} elseif ($jugadores < 3 || $jugadores > 10) {
    print "  <p class=\"aviso\">El número de jugadores debe estar entre 3 y 10.</p>\n";
    print "\n";
} else {
    $jugadoresOk = true;
}

if ($jugadoresOk) {
    $c1    = [];
    $c2    = [];
    $c3    = [];
    $total = [];

    for ($i = 1; $i <= $jugadores; $i++) {
        $c1[$i]    = rand(1, 10);
        $c2[$i]    = rand(1, 10);
        $c3[$i]    = rand(1, 10);
        $total[$i] = $c1[$i] + $c2[$i] + $c3[$i];
    }

    $maximo = max($total);

    print "  <p>La puntuación máxima ha sido <strong>$maximo puntos</strong>.</p>\n";
    print "\n";

    for ($i = 1; $i <= $jugadores; $i++) {
        print "  <p>Jugador $i:\n";
        print "    <img src=\"img/c$c1[$i].svg\" alt=\"$c1[$i]\" height=\"120px\">\n";
        print "    <img src=\"img/c$c2[$i].svg\" alt=\"$c2[$i]\" height=\"120px\">\n";
        print "    <img src=\"img/c$c3[$i].svg\" alt=\"$c3[$i]\" height=\"120px\">\n";
        print "  </p>\n";
    }
    print "\n";
}
?>