PHP variable definition and usage

Source: Internet
Author: User
Php variables must be preceded by the $ symbol and are interpreted as weak type languages. You do not need to define the type of variable values. $ str this is a variable; 1. you can concatenate strings for output, for example, echoabcdef. $ str; The Connection Symbol of the character vehicle variable is. it is different from other languages. each line of code ends. output: abced

Php variables must be preceded by the $ symbol and are interpreted as weak type languages. You do not need to define the type of variable values. $ str = "this is a variable"; 1. you can concatenate strings for output, for example, echo "abcdef ". $ str; The Connection Symbol of the character car variable is ". "is different from" + "in other languages. each code sentence ends. output: abced

Php variables must be preceded by the $ symbol and are interpreted as weak type languages. You do not need to define the type of variable values.

$ Str = "this is a variable ";

1. concatenate strings for output.

For example, echo "abcdef". $ str; the connected symbol of the character vehicle variable is "." different from other languages "+". Each sentence of code ends.

Output: abcedf. This is a variable.

2. Direct Double quotation marks reference output

Because the variable definition in php is very special, there is a $ symbol in front. Even if it is caused by double quotation marks, the interpreter will automatically interpret it as a variable.

For example, echo "abceef $ str"; enclose all double quotation marks and end.

Output: abcdef. This is a variable.

Note that the variables must be enclosed in double quotation marks before the interpreter can interpret the variables. If you enclose the variables in single quotation marks, the interpreter will not explain them. It is best to put the variables out of double quotation marks when you only use them.

For example, echo 'abcdef $ str ';

Output: abcdef $ str

Directly output the variable name without interpreting the variable value.

In php, the variable name is case sensitive. $ str and $ Str are interpreted as two different variables. this is exactly the opposite of the Function Definition in php. The function definition is case insensitive.

The variable name can contain letters, numbers, and underscores (_), but cannot start with a number.

Php variables and arrays do not need to be pre-defined or initialized. You can directly define them when using them.

For example, $ person [0] = "zhangsan"; $ person [1] = "lisi"; $ person [2] = "wangwu ";

Print_r ($ person );

Output: Array ([0] => zhangsan [1] => lisi [2] => wangwu)

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.