Wpis z mikrobloga

gdy wyołamy funkcje znowu to definiuje $x = 0

@massejferguson: no właśnie nie. Zaczyna od 0, ale nie resetuje tej wartości przy każdym wywołaniu.
Nieintuicyjne? Tak, ale to jest PHP.
  • Odpowiedz
In this example, the function incrementCounter() declares a static variable $counter and initializes it with the value 0. Each time the function is called, the value of $counter is incremented by 1 and displayed using the echo statement.

When the incrementCounter() function is invoked multiple times, the static variable retains its value between function calls. This means that the value of the $counter is not reset to 0 upon each function call,
  • Odpowiedz