Recent Posts

How to solve: Notice: Undefined variable

Happens when you try to use a variable that wasn't previously defined.
A typical example would be
foreach ($items as $item) {
    // do something with item
    $counter++;
}
If you didn't define $counter before, the code above will trigger the notice.
The correct way would be to set the variable before using it, even if it's just an empty string like
$counter = 0;
foreach ($items as $item) {
    // do something with item
    $counter++;
}

No comments:

Post a Comment