tags:

views:

18

answers:

1

Hello,

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 result 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.

Any clues?

Thanks!

+2  A: 

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.

Sarfraz
Yup, that was it.Thanks Sarfaz!
Bill
@Bill: Welcome :)
Sarfraz