Problem mit array_rand
Matthias
- php
Hallo Leute;
folgender Code:
<?php
$input = array ("01", "02", "07", "09", "11", "13");
srand ((float) microtime() * 10000000);
$output = array_rand ($input, 2);
echo $input[$output[0]];
?>
Warum bekomme ich nie Nummer "11"???
Danke,
Matthias
Hallo,
folgender Code:
<?php
$input = array ("01", "02", "07", "09", "11", "13");
srand ((float) microtime() * 10000000);
$output = array_rand ($input, 2);
echo $input[$output[0]];
?>
Warum bekomme ich nie Nummer "11"???
Erhalten habe ich 11 schon, aber in $input[$output[0]] scheinbar seltener als in $input[$output[1]].
Probiere mal etwas damit:
echo $input[$output[0]]." ".$input[$output[1]];
MfG, Thomas
Probiere mal etwas damit:
echo $input[$output[0]]." ".$input[$output[1]];
Interessant. Beim Zweiten tritt dafür die 13 nicht auf.
Das geht auch noch weiter: Wenn ich z.B. 6 Werte ausgebe, erhalte ich für [0] nur noch "02" und "09". Verrückt, oder? Das dürfte doch nicht aufgesplittet werden. Mir jetzt auch egal, ich brauche doch nur einen, also etwa
$ziehung = array_rand ($lotto);
echo $lotto[$ziehung];
...und da treten auch alle Werte auf.
Ciao,
Matthias