function incrementCounter() { static $count = 0; $count++; echo "The count is now: " . $count . "
"; } incrementCounter(); // Output: The count is now: 1 incrementCounter(); // Output: The count is now: 2 incrementCounter(); // Output: The count is now: 3
class Counter { public static $count = 0; public static function increment() { self::$count++; echo "The count is now: " . self::$count . "In this example, the static variable `$count` is defined within a class and can be accessed using the `self::$count` syntax. The method `increment()` updates the value of `$count` and prints the updated count. These examples use core PHP functionality and do not require any additional package libraries.
"; } } Counter::increment(); // Output: The count is now: 1 Counter::increment(); // Output: The count is now: 2 Counter::increment(); // Output: The count is now: 3