1. Introduction to PHP variables
1. Grammar
Copy code The code is as follows:
//PHP is a weakly typed language, and the variable type is determined by the stored value
//Strongly typed language: int a = 1
$Variable name = value
2. Naming rules
1). Cannot start with a number
2).Cannot use PHP operator (-x/%&)
3). You can use PHP keyword
4). Case sensitive (php only variables and constants are case sensitive)
5). Camel case nomenclature: aaBbCc (the first letter of the first word is lowercase)
3. Variable variables
Variable names can be set dynamically, for example: $$var
4. Reference assignment
Copy code The code is as follows:
$a=1;
$b=&$a; //Assign the value of the memory address of $a to $b
$a=2;
echo $b //The last value is equal to 1
2. Variable data type
1. Four kinds of scalars
Copy code The code is as follows:
int (integer), bool (Boolean), float, double (floating point), string (string)
2. Two composite types
Copy code The code is as follows:
Array: array()
Object: object
For example: $var = new mysqlli('localhost','root','123455')
3. Two special types
Copy code The code is as follows:
resource (resource) For example: $var = fopen('test.php','r')
Null (empty type) case-insensitive
3. Common functions
Copy code The code is as follows:
isset() //Whether the variable exists, a value of null means it does not exist
unset() //Release variables
var_dump() //Check the type of variable or value
empty() //Returns true when the variable does not exist or is empty
settype($a,int) //Set variable type
gettype() //Get variable type
4. Variable declaration method
Copy code The code is as follows:
$int = 10 //Integer 4 bytes, maximum value 2³²
$float = 3.14E⁴ //The floating point type is equal to 3.14X10⁴
$bool = false //true is true
$str = "string" //Variables and escape characters can be parsed in double quotes
//You cannot use escape characters, but you can escape the single quote itself. For example, $str = 'a'a''
$str = 'string'
Declare strings using delimiters