PHP/Language Basics/Static

Материал из Web эксперт
Перейти к: навигация, поиск

Use static variable defined in function

   <source lang="html4strict">
<?php
 increment ();
 increment ();
 increment ();
 function increment (){
     static $a=0;
     echo $a;
     $a++;
 }    
 ?>
          
      </source>
   
  


Using the static Statement to Remember the Value of a Variable Between Function Calls

   <source lang="html4strict">

<html> <head> <title>Using the static Statement to Remember the Value of a Variable Between Function Calls</title> </head> <body> <?php function aFunction( $txt ) {

    static $numCalls = 0;
    $numCalls++;
print "

$numCalls. $txt

";

} aFunction("A");

print("static called

"); aFunction("B"); print("called again<p>"); ?> </body> </html> </source>