Questions about global! Solutions

Source: Internet
Author: User
Questions about global!
I have found that many programs, including Dede, like to declare a global variable in a function, but I have searched the entire site, and I have not seen an externally defined global variable with the same name.

For example, the following example:


function SetVar ($k, $v)
{
Global $_vars;
if (!isset ($_vars[$k]))
{
$_vars[$k] = $v;
}
}

function GetVar ($k)
{
Global $_vars;
return Isset ($_vars[$k])? $_vars[$k]: ";
}

Here $_vars; For the first time in the SetVar function, does it mean that a global variable is defined here, and then the GetVar function below

$_var and $_var in other places are the same global variables?

What's the point of doing this?





------Solution--------------------
Global if this variable is not present, it will be created as a globals variable.
------Solution--------------------
is to declare a variable as global, and the entire project remains unique throughout the run!
------Solution--------------------
It is usually defined on the portal page or on the page where the variable is uniformly defined.

This is a declaration, not a definition. All variables in PHP are likely to be global variables
------Solution--------------------
discuss
I have found that many programs, including Dede, like to declare a global variable in a function, but I have searched the entire site, and I have not seen an externally defined global variable with the same name.

For example, the following example:


function SetVar ($k, $v)
{
Global $_vars;
if (!isset ($_vars[$k]))
{
$_vars[$k] = $v;
}
}

function GetVar ($k ...
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.