hey all
can anyone please tell me what i am doing wrong.
i want to obtain the frequency of each random number that i have saved to a text file.
i read the file into an array and then apply the array_count_values function, however all i get is the following output:
Array ( [37 45 23 6 2 29 ] => 1 [3 19 7 45 38 44 ] => 1 [10 20 16 32 2 17 ] => 1 [20 27 15 41 32 21 ] => 1 [25 4 11 10 36 24 ] => 1 )
The problem is that i dont want the numbers to be treated as sets but as individual elements so as to determine their frequency.
here is my code
function lotto_six() {
$lotto = array();
while (count($lotto)<6) {
$num = mt_rand(1, 45);
if (!in_array($num, $lotto)) {
$lotto[]=$num;
}
}
return $lotto;
}
$fp = fopen("lotto.txt","w");
for($i=1; $i<=5; $i++){
$lotto = lotto_six();
foreach($lotto As $index => $value){
echo $value."\n";
fwrite($fp, $value."\t");
}
echo"<br>";
fwrite($fp, "\n");
}
fclose($fp);
$lotto_frequency = file("./lotto.txt");
$lotto_frequency = array_count_values($lotto_frequency);
print_r($lotto_frequency);
the above code gets 5 sets of 6 random numbers from 1 to 45 and displays them to screen and saves them to a file.
any help much appreciated
thanks in advance