Was sagen die Profis zu folgendem code :
1. Ist dieser code soweit ok ?
2. Wie könnte man das Ganze mit weniger code realisieren ?
Bin auf eure Antworten gespannt
PHP-Code:
$num = array(); // Leeres Array erzeugen.
$zz1 = rand(1,6); // 1. Zufallszahl erzeugen.
array_push($num, $zz1); // 1. Zufallszahl in Array schreiben.
$zz2 = rand(1,6); // 2. Zufallszahl erzeugen.
while (in_array($zz2, $num)) // Prüfen, ob 2. ZZ im Array vorhanden.
{
$zz2 = rand(1,6); // Wenn ja, 2. ZZ neu erzeugen.
}
array_push($num, $zz2); // 2. Zufallszahl in Array schreiben.
$zz3 = rand(1,6); // 3. Zufallszahl erzeugen.
while (in_array($zz3, $num)) // Prüfen, ob 3. ZZ im Array vorhanden.
{
$zz3 = rand(1,6); // Wenn ja, 3. ZZ neu erzeugen.
}
array_push($num, $zz3); // 3. Zufallszahl in Array schreiben.
echo $num[0]."".$num[1]."".$num[2]; // Alle drei Zahlen anzeigen.
2. Wie könnte man das Ganze mit weniger code realisieren ?
Bin auf eure Antworten gespannt

Kommentar