PHP supports 8 types of raw data
Four types of scalar:
Boolean | Integer | Float (as Double) | String
Two kinds of composite types:
Array | Object
Two special types of
Resource | Null
Among them, the maximum value of the shaping depends on the machine, Php_int_max is the maximum value of the storage;
If you want to see the value and type of an expression, use the Var_dump () function to view
The GetType () function can be used to get the type of expression, and then to debug;
The Is_type () function can view a type:
Eg:is_int () | Is_string () | etc
Cast a variable to a type by using the Settype () function;
Integer overflow: If a number exceeds the range of int, it is interpreted and the result of the operation is returned to float;
======================================================
A string is expressed in 4:
(1) Single quotation mark
In single quotes, except ' and \, two characters need to be escaped, and any other backslash will be the backslash itself;
(2) Double quotation marks
Special characters can be resolved in double quotation marks
\ n line Break | \ r Enter | \ t Horizontal tab | \e ESCAPE | \f Page Change | \ \ Backslash | \$ USD | \ "Double quotation marks
(3) Heredoc structure: <<< lable
After the operator to provide an identifier, and then the number, followed by the string itself, and finally with the previously defined identifier as the end flag, the end of the reference identifier must be in the first column of the row.
eg
1 $str = <<<eoo2 HELLO3 Wold 4 eoo;
View Code
(4) Nowdoc structure:<<< ' lable '
The HEREDOC structure resembles a double-quote string, and Nowdoc resembles a single-quote string without parsing. Suitable for embedding PHP code or other interrupted text without having to transfer special characters within it. Unlike Heredoc, tokens need to be marked with single quotes.
(5) Variable resolution
When a string is defined in double quotation marks or heredoc, the variable is parsed.
When PHP encounters a $, it combines as many representations as possible to form a valid variable name. Therefore, you can use curly braces {} to define the bounds of the variable name.
===================================================
Array
Arrays are defined by array (), and the arrays in PHP are actually an ordered map that associates values to the keys.
5.4 can use [] instead of array ()
eg
$array Array ("foo" = "bar"); $array = ["foo" = "Bar"];
View Code
If more than one cell in the array definition uses the same key name, only the last one is used, and the previous is overwritten.
Key is optional. If not specified, PHP will automatically use the maximum integer key name previously used plus 1 as the new key name.
=======================================================
Simple syntax for object:
1<?PHP2 classFoo3 {4 functionDo_doo ()5 {6 Echo"Doing foo";7 }8 }9 $bar=Newfoo;Ten $bar-Do_foo (); One?>
View Code
Walk into php-data type and string syntax