Introduction of PHP Variables
1. Grammar
Copy Code code 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 numbers
2). Cannot use PHP operator (+-x/%&)
3). You can use the PHP keyword
4). Case Sensitive (PHP is only variable, constant case sensitive)
5). Hump nomenclature: AABBCC (first letter lowercase)
3. Variable variable
Variable names can be set dynamically, for example: $ $var
4. Reference Assignment
Copy Code code as follows:
$a = 1;
$b =& $a; Assigns the value of the $a memory address to $b
$a = 2;
echo $b//Last value equals 1
Second, variable data types
1, four kinds of scalar
Copy Code code as follows:
int (integer), bool (Boolean), float,double (floating-point penalty), string (string)
2, two kinds of compound
Copy Code code as follows:
Arrays: Array ()
Objects: Object
For example: $var = new Mysqlli (' localhost ', ' root ', ' 123455 ')
3, two kinds of special types
Copy Code code as follows:
Resource (resources) For example: $var = fopen (' test.php ', ' R ')
Null (NULL type) is case-insensitive
Iii. Common functions
Copy Code code as follows:
Isset ()///variable exists, value NULL indicates no
Unset ()//release variables
Var_dump ()//Check the type of variable or value
Returns True if Empty ()///variable does not exist or is empty
Settype ($a, int)//Set Variable type
GetType ()//Get variable type
Four, variable declaration method
Copy Code code as follows:
$int = 10//int 4 bytes, maximum 2³²
$float = 3.14e⁴//floating-point type equals 3.14x10⁴
$bool = False//true is true
$str = "string"//double quotes to resolve variables and escape characters
You cannot use escape characters, but you can escape the single quotes themselves such as $str = ' a\ ' a\ '
$str = ' string '
declaring strings with delimiters