I've got an array, but when I try to use it, I get the Undefined variable notice.
Here's the relevant lines:
$varEvents = array();
...
if ($selectedResult) {
while ($row = mysql_fetch_assoc($selectedResult)) {
array_push($varEvents, $row['eventID']);
}
mysql_free_result($selectedResult);
}
...
print_r($varEvents);
if (is_array($varEvents)) {
if (count($varEvents) > 0) {
if (in_array($id, $varEvents)) {
$varRegistered = 1;
}
}
unset($varEvents);
}
and the re开发者_如何学JAVAsult shows as:
Array ( [0] => 4 ) Notice: Undefined variable: varEvents in /home/.../www/registration.php on line 143 Notice: Undefined variable: varEvents in /home/.../www/registration.php on line 145
line 143: print_r($varEvents); line 145: if (is_array($varEvents)) {
All relevant lines are in the same loop and I do get most of the results I expect, except $varRegistered never changes to 1 and that messes up my result.
It is most likely because of this line:
unset($varEvents);
You are unsetting the variable within the loop and next iterations don't find it again.
精彩评论