1
I created a structure with some loops however php is returning me that the foreach arguments are invalid... I’m not sure if this structure is correct, so I’d like someone to let me know if this is correct or not:
for($x=1; x<=$n_cartelas_registradas; $x++) {
$contador[$x] = 0;
foreach($cartela[$x] as $n_cartela=>$numero){ //linha retornando erro
for($a=0; $a<=$n_sort; $a++){
if($numero == $sorteados_array[$a]){
$contador[$x]++;
}
}
}
}
All variables used have values.
The cartela array has the following structure: $cartela[1] = array (n, q, e, r, t);
and these values are not arrays. That is, it is two-dimensional. Already the $sorteados_array
is as follows: $sorteados_array[0] = x;
i.e.; it is a one-dimensional array.
So the foreach arguments can be written that way? If yes, where can the error be? If not, how can I get the expected result correctly? Thank you.
N, q, e, r, t are not arrays but is two-dimensional? It’s not at all clear.. Please post a $cartela dump
– gmsantos
By your code I estimate that you are forgetting to initialize any of the arrays inside the $cartela; variable.?
– jlHertel
We’d really need to see what’s on
$cartela
. But I broke your loop of1
until$n_cartelas_registradas
. Shouldn’t be of0
to$n_cartelas_registradas - 1
?– bfavaretto
I was wrong to write... They are arrays.
– HiHello