Photoshop CS5 official Chinese cracked version download PHP variables summary Novice Recommendation

Source: Internet
Author: User
There is no need to display declaration variables in PHP, and variable declarations can be performed concurrently with assignments. Good programming habits are: All variables should be declared before use, preferably with comments.
One, the assignment of variables
You can assign a value to a variable after it is declared in two ways: value assignment and reference assignment.
1. Value Assignment
$color = "Red";
$sum = 12+ "15"; /* $sum = 27 */
2. If you want two variables to point to the same copy of a value, you need to assign a value by reference.
Reference assignment
The variable that is created is the same as the content referenced by another variable, and if more than one variable references the same content, any one of the variables is modified and will be reflected on the remaining variables.
Example:
$value 1 = "Hello";
$value 2 = &value1; /* $value 1 and $value 2 both equal "Hello". */
$value 2 = "Goodbye"; /* $value 1 and $value 2 both equeal "Goodbye". */
?>
Ii. Scope of variables
A variable can be declared anywhere in a PHP script, but declaring a variable's position greatly affects the scope of the access variable. This accessible scope is known as scope (scope).
The scope of the PHP variable in 4:
Local variables
function parameters
Global variables
static variables
1. Local Variables
A variable declared in a function is considered a local variable and can only be referenced in a function, and the variable and the corresponding value are revoked when the function that declares the variable is exited. Eliminates the possibility that variables that cause global access are intentionally or unintentionally modified.
$x = 4;
function Assignx () {
$x = 0;
print "\ $x inside function is $x.
" ;
}
Assignx ();
print "\ $x outside of function is $x.
" ;
The result of the code execution is:
$x inside function is 0.
$x outside function is 4.
2. Function parameters
As with other programming languages, any function that accepts parameters must declare them in the first part of the functions. Although these parameters accept values outside the function, they are no longer accessible after exiting the function. (except for parameters passed by reference)
For example:
function x10 ($value) {
$value = $value * 10;
return $value;
}
The function is finished and the parameters are about to be revoked.
3. Global variables
As opposed to local variables, global variables can be accessed from anywhere in the program. When you change a global variable in a function, you need to display the variable as a global variable in the function, as long as you add global to the variable in the function.
For example:
$somevar = 15;
function Addit () {
GLOBAL $somevar;
$somevar + +;
Print "Somevar is $somevar";
}
Addit ();
The $somevar should show a value of 16, but if the GLOBAL $somevar is removed; In this line, the variable $somevar will be implicitly set to 0, plus 1, and the last displayed value is 1.
Another way to declare a global variable is to use PHP's $global array, as follows:
$somevar = 15;
function Addit () {
$GLOBALS [' Somevar ']++;
}
Addit ();
Print "Somevar is". $GLOBALS [' Somevar '];
The return value is as follows: Somevar is 16.
4. Static variables
Static scope. The function arguments of the normal variable are undone at the end of the function, but the static variable does not lose value when the function exits, and this value can be preserved when the function is called again. You can declare a static variable by adding the keyword static before Sheng Liangming.
STATIC $somevar;
Consider an example:
function Keep_track () {
STATIC $count = 0;
$count + +;
Print $count;
Print "
" ;
}
Keep_track ();
Keep_track ();
Keep_track ();
Keep_track ();
If the $count is not indicated as static (the corresponding $count is a local variable), the output will be
1
1
1
1
Because $count is static, it retains the previous value each time the function is executed. The output is as follows:
1
2
3
4
Static scopes are useful for recursive functions. Recursive functions (recursive function) are a powerful programming concept, which is a function that can call itself repeatedly until a certain condition is met.
5. Super Global variables of PHP
PHP provides a number of useful pre-defined variables that can be accessed at the person and location where the script is executed to provide a large amount of information about the environment. These variables allow you to obtain detailed information about the current user session, the user operating system environment, and the local operating environment. PHP creates some variables, while the availability and value of many other variables depend on the operating system and Web services.
Output all predefined variables:
foreach ($_server as $var = = $value) {
echo "$var and $value
" ;
}
Show the IP address of the user:
Print "hi! Your IP address is ". $_server[' remote_addr ');
To use a predefined array of variables in PHP, you must enable configuration parameter Track_vars in the php.ini file.

The above describes the Photoshop CS5 the official Chinese cracked version of PHP to download the variable summary of the novice recommendation, including the Photoshop CS5 the official Chinese version of the download of the content, I hope that the PHP tutorial interested friends helpful.

  • Related Article

    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.