The global statement brings an outside variable "into" a function. In our previous tutorial, you learned that a variable created outside of a PHP function is not available to be used by that function. Usually you will get around this problem by passing an argument when you call the function.
Another way to make an "outside" variable available to a function is to use the PHP global statement. The global statement brings the outside variable "into" the function. Let's take a look at the code.
This tells the program that the following is a PHP function. print_name is the name of the function and is used to ID the function to the program. Although we are not passing any arguments to the function, we still need to follow the function name with parenthesis. Inside the opening { and closing } is the code for the body of the function. . .
This is the global statement that will make the value to the $first_name variable available to the function. As you can see, this statement ends with a semicolon.
| |||||||