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.