Hallo
meine Aufgabe ist es, eine Funktion genTipps($n) zu implementieren, die die Anzahl der zu erzeugenden Tippreihen (jede Zeile enthält eine Tippreihe) enthält und ein 2-dimensionales Array zurückliefert. Ich habe das leider nur ohne die Funktion geschafft.
Ich hoffe, dass ihr mir hier weiterhelfen könnt. Für ein paar Tipps wäre ich sehr dankbar.
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="description" content="Geschachtelte Schleifen" />
<meta name="keywords" content="HTML, PHP" />
<meta name="author" content="ews13" />
<link rel="stylesheet" type="text/css" href="css/textFormat.css" />
<link rel="stylesheet" type="text/css" href="css/formular.css" />
<link rel="stylesheet" type="text/css" href="css/myTables.css" />
</head>
<body>
<?php
if (!isset($_REQUEST['go'])) {
// Aufruf ohne Größenangabe: Zeige das Eingabefeld
print('<h4>Anzahl von Tippreihen eingeben</h4>
<form action="eurojackpotUeb.php" method="POST">
<p><input type="text" name="n"></p>
<p><input type="submit" value="abschicken" name="go"></p>
</form>
');
} else {
//function genTipps($n) {
// Anzahl Tippreihen in PHP-Variable speichern
$n = $_POST['n'];
print('<h4>Tabelle mit Tippreihen für Euro Jackpot</h4>
<article>');
// Zeilen erzeugen
for ($i = 0; $i < $n; $i++) $P[$i] = array();
// Zeilen besetzen
for ($i = 0; $i < $n; $i++) {
for ($j =0; $j < 5; $j++) {
do {
$zahl = rand(1,50);
} while (in_array($zahl,$P[$i]));
$P[$i][$j] = $zahl;
} // for all j
sort($P[$i]);
$zahl1 = rand(1,10);
do {
$zahl2 = rand(1,10);
} while ($zahl1 == $zahl2);
if ($zahl1 < $zahl2) { $P[$i][] = $zahl1; $P[$i][] = $zahl2; }
else { $P[$i][] = $zahl2; $P[$i][] = $zahl1; }
} // for all i
print('<table id="gradient-style">
<thead>
<tr>
<th>Nr.</th>
<th colspan="5">Tippreihe</th>
<th colspan="2">Eurozahlen</th>
</tr>
</thead>
<tbody>
');
for ($i = 0; $i < $n; $i++) {
print('<tr><td>' .($i+1) .'</td>');
for ($j =0; $j < 7; $j++) {
print('<td>' .$P[$i][$j] .'</td>');
}
print('</tr>');
}
print(' </tbody>
</table>
</article>
');
} // eof Eingabe vorhanden
?>
</body>
</html>
meine Aufgabe ist es, eine Funktion genTipps($n) zu implementieren, die die Anzahl der zu erzeugenden Tippreihen (jede Zeile enthält eine Tippreihe) enthält und ein 2-dimensionales Array zurückliefert. Ich habe das leider nur ohne die Funktion geschafft.

Ich hoffe, dass ihr mir hier weiterhelfen könnt. Für ein paar Tipps wäre ich sehr dankbar.

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="description" content="Geschachtelte Schleifen" />
<meta name="keywords" content="HTML, PHP" />
<meta name="author" content="ews13" />
<link rel="stylesheet" type="text/css" href="css/textFormat.css" />
<link rel="stylesheet" type="text/css" href="css/formular.css" />
<link rel="stylesheet" type="text/css" href="css/myTables.css" />
</head>
<body>
<?php
if (!isset($_REQUEST['go'])) {
// Aufruf ohne Größenangabe: Zeige das Eingabefeld
print('<h4>Anzahl von Tippreihen eingeben</h4>
<form action="eurojackpotUeb.php" method="POST">
<p><input type="text" name="n"></p>
<p><input type="submit" value="abschicken" name="go"></p>
</form>
');
} else {
//function genTipps($n) {
// Anzahl Tippreihen in PHP-Variable speichern
$n = $_POST['n'];
print('<h4>Tabelle mit Tippreihen für Euro Jackpot</h4>
<article>');
// Zeilen erzeugen
for ($i = 0; $i < $n; $i++) $P[$i] = array();
// Zeilen besetzen
for ($i = 0; $i < $n; $i++) {
for ($j =0; $j < 5; $j++) {
do {
$zahl = rand(1,50);
} while (in_array($zahl,$P[$i]));
$P[$i][$j] = $zahl;
} // for all j
sort($P[$i]);
$zahl1 = rand(1,10);
do {
$zahl2 = rand(1,10);
} while ($zahl1 == $zahl2);
if ($zahl1 < $zahl2) { $P[$i][] = $zahl1; $P[$i][] = $zahl2; }
else { $P[$i][] = $zahl2; $P[$i][] = $zahl1; }
} // for all i
print('<table id="gradient-style">
<thead>
<tr>
<th>Nr.</th>
<th colspan="5">Tippreihe</th>
<th colspan="2">Eurozahlen</th>
</tr>
</thead>
<tbody>
');
for ($i = 0; $i < $n; $i++) {
print('<tr><td>' .($i+1) .'</td>');
for ($j =0; $j < 7; $j++) {
print('<td>' .$P[$i][$j] .'</td>');
}
print('</tr>');
}
print(' </tbody>
</table>
</article>
');
} // eof Eingabe vorhanden
?>
</body>
</html>
Kommentar