1) PHP supports basic data types as shown 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 a variable can use or be visible in a script. PHP has 6 basic scope rules:
2.1) built-in super global variables can be used and visible anywhere in the script;
2.2) constants, once declared, will be visible globally;
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 can be persisted during multiple executions of the function;
2.6) variables created inside the function are local to the function, and when the function terminates, the variable does not exist.
Note: The complete list of super global variables is as follows:
$GLOBALS--All global variable arrays;
$_server--server environment variable array;
$_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--the array of variables entered by all users, including the input contained in $_get, $_post, and $_cookie;
An array of $_session--session variables.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
PHP Data types and scope of variables