Use variables in PHP

Source: Internet
Author: User

1. Variable declaration:

If you use data multiple times, declare it as a variable. $ Variable name = Value In a strongly typed language (C, Java), you must specify the type before declaring a variable. PHP is a weak language, and the variable type is determined by the stored value. Isset (); determines whether a variable exists Unset (); Delete variable

 

2. variable name:

1. You must use "$" before the variable. This symbol must be included in the declaration and use. 2. It cannot start with a number. 3. You cannot use the PHP operator number +-*/% & and so on. 4. php can use the system keyword as the variable name 5. Note: PhP variables are case sensitive (only variables and common variables are case sensitive and others are not case sensitive) 6. The variable name must be meaningful. You can use English words or Chinese pinyin. Aaa bbb ccc

$ Aaabbbccc variable naming Style

 

3. Variable:

$ One = "###";

$ Two = "one ";

$ Three = "two ";

$ Four = "three ";

Echo $ four; --- two

Echo $ four; --- one

 

4. assign values to variables:

Use the "&" symbol to add the variable to be assigned a value (source variable) Example: $ one = 1; $ Two = & $ one;

5. Variable type:

PHP is a weak language PHP has eight types Four scalar Integer: int, integer Boolean: bool, Boolean Float, double, real String: String Two composite types Array: Array Object Two special types Resource Type: Resource Null type: NULL  Var_dump (variable or value); // you can view both the type and data of the variable or value.

6. Declaration of various types of variables:

Integer declaration method:

$ Int = 16; -- decimal

$ Int = 045; -- a value starting with 0 indicates octal.

$ Int = 0xf; -- a hexadecimal value starting with 0x or 0x

Floating point declaration method:

$ Float = 3.14e5; --- indicates the 5th power of 3.14*10

Boolean declaration method:

The following are all false cases:

$ Bool = false;

$ Bool = 0;

USD bool = 0.00;

$ Bool = "";

$ Bool = "";

$ Bool = NULL;

$ Bool = "0 ";

$ Bool = array ();

 

String declaration:

1. Single quotes and double quotes can both declare strings.

2. The declared string has no length limit.

3. In double quotation marks, both variables can be directly parsed and escape characters can be directly used.

4. Variables cannot be parsed or escape characters in single quotes (you can escape single quotes ).

, You can also escape the Escape Character "\")

5. You cannot use double quotation marks in double quotation marks.

6. It is best to use single quotes

Delimiter declaration string

$ STR = <p

Fsdfdsfsfsfs "" ''' fsfs

P;

Note: The preceding P cannot have any symbols. Press enter.

The following P is written in the top lattice, and P is a custom string.

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.