<?php

//Anzahl aus Gesamt.
function Lotto($anzahl, $gesamt)
{
$spiel = array();

for ($i=0; $i<$gesamt; $i++)
{
$spiel[] = $i+1;
}

//die Funktion shuffle vermischt die Schlüsselelemente zufällig.
srand ((float)microtime()*1000000);
shuffle ($spiel);

//die Funktion array_slice($array, $schluessel, $anzahl) trennt die ersten 6 ($anzahl) Elemente heraus.
$result = array_slice($spiel, 0, $anzahl);

//die Funktion sort() sortiert das Array.
sort($result);

return $result;
}

//Anzahl aus Gesamt. Also 6 aus 49. Funktionsaufruf
$myLotto = Lotto(6, 49);
foreach($myLotto as $schluessel => $wert)
{
echo ("$wert
");
}

?>

8
9
10
20
30
43