PHP variable definition and usage

Source: Internet
Author: User

PHP variables must be preceded by a $ sign, and are interpreted weakly typed languages that do not need to define the type of the variable value at the time of definition.

$str = "This is a variable";

1. When the output can be used to stitch the string method

such as: Echo "abcdef". $str; The connection symbol for the character car variable is "." Differs from the "+" in other languages. Each code is ";" End.

Output: ABCEDF This is a variable.

2. Direct double Quote quote output

Because PHP's variable definition is very special, with the $ sign in front, even if enclosed in double quotes, the interpreter automatically interprets it as a variable.

such as: echo "ABCEEF$STR"; Enclose all double quotes to ";" End.

Output: abcdef This is a variable.

It is important to note that the interpreter must be enclosed in double quotation marks to explain the variables. If the interpreter is not interpreted in single quotation marks. It's best to put the variables outside the double quotes when you use them.

such as: Echo ' abcdef$str ';

Output: Abcdef$str

The direct output of the variable name does not explain the value of the variable.

Another thing to note about variables in PHP is that variable names are sensitive to letter case, $STR and $STR will be interpreted as two different variables. Just as opposed to the function definition in PHP, the function definition is not case-sensitive.

Variable names can include letters, numbers, and _ (underscores) but cannot start with a number.

PHP variables and arrays do not need to be pre-defined and initialized, and can be defined directly when used.

such as: $person [0]= "Zhangsan"; $person [1]= "Lisi"; $person [2]= "Wangwu";

Print_r ($person);

Output: Array ([0] = Zhangsan [1] = lisi [2] = Wangwu)

PHP variable definition and usage

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.