0

I'm having an issue with a var value, that should increase everytime a function runs.

Illustrative code:

$i = 1;
function() {
     ...
     $i++;
}

This function is called on a page multiple times, and i need that $i value to be used on a lot of stuff inside it.

Thing is, $i value always ends up with the value equal to 1.

Any clues?

Thanks

João Colucas
  • 249
  • 1
  • 3
  • 14

1 Answers1

0

The $i in the function is not the one you defined outside it.

Here's a resolution:

$i = 1;
function test(&$i) {
    $i++;
}

test($i);
Frederick Zhang
  • 3,593
  • 4
  • 32
  • 54