Error with Foreach arguments

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 would like someone to inform me if this is correct: p>

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 array 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. The $sorteados_array is as follows: $sorteados_array[0] = x; ie; is a one-dimensional array.

So the foreach arguments can be written this way? If so, where could be the error? If not, how can I get the expected result correctly? Thank you.

    
asked by anonymous 04.09.2014 / 04:16

1 answer

2

The dollar sign has been missing in the variable $x of the condition.

for($x=1; x <= $n_cartelas_registradas; $x++)
----------^

Switch By:

for($x=1; $x <= $n_cartelas_registradas; $x++) {
    
04.09.2014 / 15:39