Working with Static Variables in Functions : static variables « Language Basics « PHP






Working with Static Variables in Functions

 
<?php

    function statictest() {

        static $count = 0;

        $count++;

        return $count;

    }

    statictest();
    statictest();

    $foo = statictest();

    echo "The statictest() function ran $foo times.<BR>";

?>
  
  








Related examples in the same category

1.A static variable remembering its last value
2.Using the static Statement to Remember the Value of a Variable Between Function Calls
3.Using the static modifier to change a member or method so it is accessible without instantiating the class
4.static variables