PHP/Language Basics/Global — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 10:37, 26 мая 2010
the global statement is used
<?php
$ilike = "Rock";
function music (){
global $ilike;
echo "I love listening to $ilike music!", "\n";
}
music ();
?>
Using the global Statement to Remember the Value of a Variable Between Function Calls
<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 "<h1>$num_of_calls. $txt</h1>";
}
andAnotherThing("A");
print("Called<p>");
andAnotherThing("B");
print("Called again<p>");
?>
</body>
</html>