In PHP I want to know the differences between the GLOBAL and GLOBALS.
Some example:
print_r($GLOBALS);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
That are two different things related to the same: global variables.
$GLOBALS– PHP superglobal array representing the global variable table accessible as an array. Because it’s a superglobal, it’s available everywhere.global– Keyword to import a specific global variable into the local variable table.Then you asked:
That’s wrong, you can access session and cookie variables by using
$GLOBALS:However
$_SESSIONis a superglobal as well, so you don’t need to use either$GLOBALSnorglobalto access session variables from everywhere:Same applies to
$_COOKIE.