PHP Data types and scope of variables

Source: Internet
Author: User
Tags type null

1) PHP supports the following basic data types as seen below:

An integer (integer), float (floating-point), String (String), Boolean (Boolean), Array (array), object, and two special types: null (empty), resource (Resource).

Note: A variable that is not assigned, has been reset, or is assigned a special value of NULL is a variable of type null.

A specific built-in function, such as a database function, returns a variable of type resource.

2) Scopes are scopes that can be used or visible by a variable in a script. PHP has 6 main scope rules:

2.1) built-in super global variables can be used and visible anywhere in the script;

2.2) constant. Once it is declared. will be able to be globally visible.

2.3) The global variables declared in a script are visible throughout the script;

2.4) When a variable used inside a function is declared as a global variable, its name is the same as the global variable name;

2.5) A variable that is created inside a function and declared as static cannot be visible outside the function, but is able to persist the value during multiple runs of the function.

2.6) variables created inside the function are local to the function. When the function terminates, the variable does not exist.

Note: The complete list of super global variables, as seen below:

$GLOBALS--An array of all global variables.

An array of $_server--server environment variables.

$_get--the array of variables passed to the script by the GET method;

$_post--the array of variables passed to the script via the POST method;

An array of $_cookie--cookie variables.

$_files--array of variables related to file uploads;

An array of $_env--environment variables;

$_request--An array of variables entered by all users. Includes input from $_get, $_post, and $_cookie.

An array of $_session--session variables.

PHP Data types and scope of variables

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.