PHP study notes (2): variable details and study notes. PHP learning notes (2): variable details, learning notes I. PHP variable introduction 1. syntax copy code: PHP is a weak language, the variable type is determined by the stored value. PHP learning notes (2): variable details, learning Notes Details
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
Explain (2): variable details, learning Notes 1. PHP variable introduction 1. syntax code: // PHP is a weak language, and the variable type is determined by the stored value...