A detailed introduction to PHP variables

Source: Internet
Author: User
Tags variable scope
What is a global variable? A global variable, also known as an external variable, is defined outside the function and is scoped to the end of the program file, starting at the definition of the variable. Unlike other programming languages, global variables are not automatically set to be available. In the previous section we introduced the local variables of the scope of the PHP variable, in PHP, because the function can be treated as a separate program snippet, so the local variable overrides the visibility of the global variable, so the global variable cannot be called directly in the function. The format of its code is as follows: <?php $one = 10; $two = 20; The test cannot use global variables directly inside the function $one and $two function sum () {//Two variables that are newly declared inside the function and do not have an initial value assigned

1. What are global variables? Examples of global variables for the range of PHP variables

Summary: A global variable, also known as an external variable, is defined outside the function and is scoped to the end of the program file, starting at the definition of the variable.

2. What is a local variable? Example of a local variable in the scope of a PHP variable

Summary: The scope of a variable is also its scope of entry. Most PHP variables have only a single scope of use, and also include the files introduced by include and require.

3. PHP variable function and function reference and dereference instance detailed

Introduction: In PHP is to support variable functions, first define some functions, then declare a variable, use variables to invoke different functions, and then constantly re-assign values. Below we will introduce a concrete example of how variable functions are used.

4. Assignment of PHP variables: The difference between value passing and reference passing

Introduction: A variable refers to the amount of value that can be changed during the execution of the program, it is used to save a value, it is convenient for us to call, but there are two ways in which PHP assigns variables: value passing and reference passing, these two methods of assigning values to variables are different, this chapter, Let's take a look: the difference between value passing and reference passing

5. PHP variable Scope instance detailed

Summary: Variables are used, to conform to the definition rules for variables. Variables have to be used in a valid range, and if the variable goes beyond a finite range, the variable is meaningless, as if we had 100 dollars, we can buy 100 dollars or less, if the item exceeds 100 yuan, then these 100 pieces will not be used. 100 dollars is the equivalent of this variable, and the range within 100 blocks is equivalent to the scope.

"Related question and answer recommendation":

There are variables in PHP variable names

Query for PHP variables and objects

Ask the PHP variable scope of the problem ~ ~ ~

PHP References and PHP variables not used

thinkphp How to escape the curly braces of HTML template files?

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.