PHP/Language Basics/Global

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

the global statement is used

   <source lang="html4strict">

<?php

 $ilike = "Rock";
 function music (){
     global $ilike;
     echo "I love listening to $ilike music!", "\n";
 }
 music ();

?>

      </source>
   
  


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

   <source lang="html4strict">

<html> <head> <title>Using the global Statement to Remember the Value of a Variable Between Function Calls</title> </head> <body> <?php $num_of_calls = 0; function andAnotherThing( $txt ){

   global $num_of_calls;
   $num_of_calls++;
print "

$num_of_calls. $txt

";

} andAnotherThing("A");

print("Called

"); andAnotherThing("B"); print("Called again<p>"); ?> </body> </html> </source>