A static variable remembering its last value : static variables « Language Basics « PHP






A static variable remembering its last value

 
<?php

function birthday(  ){
    static $age = 0;

    $age = $age + 1;

    echo "Birthday number $age<br />";
}

$age = 30;

birthday(  );
birthday(  );

echo "Age: $age<br />";

?>
  
  








Related examples in the same category

1.Using the static Statement to Remember the Value of a Variable Between Function Calls
2.Using the static modifier to change a member or method so it is accessible without instantiating the class
3.static variables
4.Working with Static Variables in Functions