function myFunction() { static $count = 0; $count++; echo "Function has been called " . $count . " times"; } myFunction(); // Function has been called 1 times myFunction(); // Function has been called 2 times myFunction(); // Function has been called 3 times
function getConfigValue($key) { static $config = array( 'db_name' => 'my_database', 'db_user' => 'my_username', 'db_pass' => 'my_password' ); return $config[$key]; } echo getConfigValue('db_name'); // my_database echo getConfigValue('db_user'); // my_username echo getConfigValue('db_pass'); // my_passwordIn this example, a function called "getConfigValue" is defined that takes a key as an argument and returns the corresponding value from a static array called "$config". The array contains configuration values that remain unchanged throughout the script execution. Package Library: Standard PHP Library (SPL) Overall, PHP static default is a useful keyword that allows for the declaration of static variables with default values that remain unchanged throughout the script execution. It is a feature supported by the Standard PHP Library (SPL).