In my function, in_array not finding the numbers.
function genNumbers($min, $max, $quantity, $qtd, $sumMin = false, $sumMax = false)
{
for ($i = 0; $i <= $qtd; $i++) {
$numbers = range($min, $max);
shuffle($numbers);
$a = array_slice($numbers, 0, $quantity);
asort($a);
$x = array(14, 17);
if (in_array($x, $a)) {
continue;
}
if ($sumMin) {
if (array_sum($a) < $sumMin)
continue;
}
if ($sumMax) {
if (array_sum($a) > $sumMax)
continue;
}
foreach ($a as $key => $o) {
if (end(array_keys($a)) == $key) {
$aux = '';
} else {
$aux = ' - ';
}
echo $o . $aux;
}
echo '<br />';
}
}
Only works with a single number
if (in_array(14, $a)) {
continue;
}
E.g:
<?= genNumbers(1, 25, 15, 100, 201, 201) ?>
This example continues returning values with 14 and 17. Like:
- 2 - 5 - 6 - 7 - 9 - 11 - 13 - 14 - 16 - 17 - 18 - 19 - 21 - 22 - 25
- 1 - 3 - 6 - 7 - 8 - 11 - 13 - 15 - 17 - 18 - 20 - 21 - 22 - 23 - 25
- 1 - 3 - 5 - 6 - 8 - 11 - 12 - 15 - 17 - 19 - 20 - 21 - 22 - 24 - 25
- 2 - 3 - 5 - 8 - 10 - 12 - 15 - 16 - 18 - 19 - 20 - 22 - 23 - 24 - 25
- 3 - 4 - 7 - 8 - 9 - 10 - 13 - 14 - 15 - 17 - 20 - 21 - 23 - 24 - 25
What is wrong? Thx!