Home > Article > Backend Development > Detailed explanation of the usage of php9 super global variables (1)_PHP tutorial
Many predefined variables in PHP are "superglobal," meaning they are available throughout the entire scope of a script. They can be accessed within a function or method without executing global $variable;.
These superglobal variables are:
int main() { int a = 3; void t() { printf("%d",a); } t(); return 0; }
<?php $a = 3; function t(){ echo $a; } t(); ?>
<?php $a = 5; function t(){ $b = 2; } function w() { echo $GLOBALS['b']; echo $GLOBALS['a']; } t(); w(); ?>
Looking at the second $_SERVER, $_SERVER is an array containing information such as header, path, and script locations. The items in this array are created by the web server. There is no guarantee that every server will offer all items; servers may ignore some, or serve items not listed here. A lot of useful information can be extracted from $_SERVER. For example, $_SERVER['REMOTE_ADDR'] can get the current user's IP. Next, I use foreach to traverse the entire $_SERVER array and print it. The code is as follows:
<?php foreach($_SERVER as $key => $value){ echo "<b>$key:</b> $value<br>\n"; }
If you want to see the effect but don’t want to or can’t write now, you can check this URL. This is the effect of the sae server. http://5253.sinaapp.com/blog/server.php I uploaded it here.