There are 8 scalar types in PHP, including string (string), integer (integer), float (floating point type, also called double), boolean (Boolean type) and composite types and resources (resources) ), NULL (empty), let’s take a look below.
php data type
PHP supports eight primitive types (type).
4 scalar types:
string (string), integer (integer), float (floating point type, also called double), boolean (Boolean type)
Two compound types:
array(array), object(object)
Two special types:
resource(resource), NULL(empty)
Boolean
Syntax: To specify a Boolean value, use the keywords TRUE or FALSE. Both are case-insensitive.
When converted to boolean, the following values are considered FALSE:
1> Boolean value FALSE
2> Integer value 0 (zero)
3> Floating point value 0.0 (zero)
4> Blank string and string “0″
5> Array without member variables
6> Object without unit
7> Special type NULL (including variables that have not been set)
All other values are considered TRUE (including any resources).
Note: -1, like other non-zero values (whether positive or negative), is considered TRUE!
================================================== ==================================
Shape(integer)
Syntax: Integer values can be specified in decimal, hexadecimal or octal notation, preceded by an optional sign (- or +).
If you use octal notation, you must add 0 (zero) before the number, and if you use hexadecimal notation, you must add 0x before the number.
================================================== ===================================
string(string)
Three ways to define: single quotes, double quotes, delimiters.
String conversion:
You can convert a value to a string using the (string) notation or the strval() function.
The Boolean value TRUE will be converted to the string "1", while the value FALSE will be represented as "" (i.e. the empty string).
NULL will be converted to an empty string.
Convert string to numeric value
When a string is evaluated as a number, the following rules determine the type and value of the result.
If it contains any of the ".", "e" or "E" characters, the string is evaluated as a float. Otherwise it is treated as an integer. As shown below:
The code is as follows
|
Copy code
|
||||
$foo = 1 + “10.5″; // $foo is float (11.5)
$foo = 1 + “-1.3e3″; // $foo is float (-1299)
$foo = 1 + “bob-1.3e3″; // $foo is integer (1) | ================================================== ======================================