This article mainly introduces PHP learning notes (2): Variable details. This article describes PHP variables, variable data types, common functions, and variable declaration methods, for more information, see
I. Introduction to PHP Variables
1. Syntax
The Code is as follows:
// PHP is a weak language, and the variable type is determined by the stored value.
// Strong language: int a = 1
$ Variable name = Value
2. Naming rules
1). Cannot begin with a number
2). You cannot use the PHP operator (+-x/% &)
3). You can use the PHP keyword.
4). Case Sensitive (only variables and constants in php are case sensitive)
5). Camper naming method: aaBbCc (the first letter is lowercase)
3. Variable
Variable names can be dynamically set, for example: $ var
4. Reference Assignment
The Code is as follows:
$ A = 1;
$ B = & $ a; // assign the value of the $ a memory address to $ B
$ A = 2;
Echo $ B // The last value is 1
Ii. variable data types
1. Four scalar
The Code is as follows:
Int (integer), bool (Boolean), float, double (floating point penalty), string (string)
2. Compound
The Code is as follows:
Array: array ()
Object
Example: $ var = new mysqlli ('localhost', 'root', '123 ')
3. Two special types
The Code is as follows:
Resource (resource) Example: $ var = fopen ('test. php', 'R ')
Null (Null type) is case insensitive
Iii. Common functions
The Code is as follows:
Isset () // whether the variable exists. If the value is null, the variable does not exist.
Unset () // release the variable
Var_dump () // check the type of the variable or value
Empty () // returns true if the variable does not exist or is null.
Settype ($ a, int) // set the variable type
Gettype () // get the variable type
Iv. Variable declaration method
The Code is as follows:
$ Int = 10 // an integer of 4 bytes. The maximum value is 2 bytes.
$ Float = 3.14E small // float is equal to 3.14X10 small
$ Bool = false // true
$ Str = "string" // variables and escape characters can be parsed in double quotation marks
// Escape characters cannot be used, but single quotation marks can be escaped. For example, $ str = 'a \''
$ Str = 'string'
Declare a string using a delimiter