- time: documentation ( source)
- array_search: documentation ( source)
- array_fill: documentation ( source)
- max: documentation ( source)
- rand: documentation ( source)
- srand: documentation ( source)
<?php
function generate_result_array($where) {
return array_fill(0, count($where), 0);
}
function generator($where) {
for (;;) {
yield rand(0, count($where) - 1);
if (42 === rand(0, 100000)) {
break;
}
}
};
function main() {
$where = [ 'Péché mignon', 'McDo', 'Flunch' ];
$results = generate_result_array($where);
srand(time());
foreach (generator($where) as $result) {
$results[$result]++;
}
echo $where[array_search(max($results), $results)], "\n";
}
main();