What are the potential benefits of using "static" variables in PHP functions?
Using "static" variables in PHP functions allows you to maintain the state of a variable across multiple function calls. This can be useful for scenarios where you need to retain the value of a variable between function calls without using global variables or passing the variable as a parameter each time the function is called.
function incrementCounter() {
static $counter = 0;
$counter++;
echo "Counter: " . $counter . "\n";
}
incrementCounter(); // Output: Counter: 1
incrementCounter(); // Output: Counter: 2
incrementCounter(); // Output: Counter: 3