I have this function that in_array is not working as it should
function genNumeros($min, $max, $quantity, $qtd, $somamin = false, $somamax = 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 ($somamin) {
if (array_sum($a) < $somamin)
continue;
}
if ($somamax) {
if (array_sum($a) > $somamax)
continue;
}
foreach ($a as $key => $o) {
if (end(array_keys($a)) == $key) {
$aux = '';
} else {
$aux = ' - ';
}
echo $o . $aux;
}
echo '<br />';
}
}
It's only working if I use it this way:
if (in_array(14, $a)) {
continue;
}
Example:
<?= genNumbers(1, 25, 15, 100, 201, 201) ?>
This example continues to return values with 14 and 17 (which were not to appear):
- 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
- 3 - 4 - 7 - 8 - 9 - 10 - 13 - 14 - 15 - 17 - 20 - 21 - 23 -
What's wrong?