";
// Define a function that initializes a local variable
// (using the same as the global variable) and display its value
function show_local()
{
$number = 100;
echo "Local number: $number
";
}
// Call the function to show local variable
show_local();
// Define and call a recursive function that increments
// the global variable and a static variable on each call
function recur()
{
// To use a global variable inside a function, the declaration must include
// the global keyword (i.e., refer to a global variable defined outside)
// Be careful when using global variables.
global $number;
// Unlike other local variables, which lose their value when
// the program scope leaves the function,
// a static local variable retain their value.
// Therefore, the updated value stored in a static variable is
// recognized on each function call.
static $letter = 'A';
if ($number < 14)
{
echo "$number : $letter | ";
$number++;
$letter++;
recur();
}
}
// Call the recursive function
recur();
// Display the modified global variable value
echo "
After modifying the global variable value, Global number: $number";
?>