lottozahlen.php
Quell Code
<?php
// erste möglichekeit
$zahlen = array();
for($i=0; $i<27; $i++) {
$temp = mt_rand(1,49);
if( in_array($temp, $zahlen) ) {
$i--;
continue;
}
$zahlen[] = $temp;
//echo $temp.',';
}
// möglichkeit 2
// Array erstellen
$Lottozahlen = array();
// Schleife
for($i=0; $i<=7; $i++)
{
// Eine Zahl zwischen 1 und 49
$Ziehung = mt_rand(1,49);
// Prüfen ob Zahl bereits vorhanden
if (in_array($Ziehung, $Lottozahlen))
{
$i--;
continue;
}
// In Array laden
$Lottozahlen[] = $Ziehung;
natsort($Lottozahlen);
}
// Mit Komma trennen
$Lottozahlen = implode(',', $Lottozahlen);
//
echo "Die Lottozahlen dieser Wochen lauten: ".$Lottozahlen;
?>