: This article mainly introduces PHP learning (4)-Data Types. For more information about PHP tutorials, see. PHP supports eight types of raw data.
Four scalar types: (the scalar type is the basic type)
- Boolean (boolean)
- Integer)
- Float (float, also called double) (for historical reasons, float is also called double. php does not have single precision or double precision)
- String (string type belongs to the scalar type in PHP and belongs to the class type in Java)
Two composite types:
There are two special types:
The type of a variable is generally not set by the programmer. to be exact, it is determined by PHP at runtime based on the context used by the variable.
To view the value and type of an expression, use the var_dump () function.
If you just want to get an easy-to-understand expression of the type for debugging, use the gettype () function. To view a type, use the is_type function instead of gettype.
Example:
"; // prints out: booleanecho gettype($a_str)."
"; // prints out: stringecho gettype($an_int)."
"; // prints out: integerecho gettype($a_float)."
"; // prints out: double// If this is an integer, increment it by fourif (is_int($an_int)) { echo"an_int = ".$an_int."
"; $an_int += 4; echo"an_int = ".$an_int."
";}// If $bool is a string, print it out// (does not print out anything)if (is_string($a_str)) { echo"String: $a_str"."
";}echo var_dump($a_float, $a_bool, $a_str, $an_int);?>
Output:
booleanstringintegerdoublean_int = 12an_int = 16String: foofloat(3.14) bool(true) string(3) "foo"int(16)
Description of gettype () in the php Manual (please zoom in to see ?) :
For specific use of each type, please refer to the official PHP Manual. here I am only a reference.
'). AddClass ('pre-numbering '). hide (); $ (this ). addClass ('Has-numbering '). parent (). append ($ numbering); for (I = 1; I <= lines; I ++) {$ numbering. append ($ ('
'). Text (I) ;}; $ numbering. fadeIn (1700) ;}) ;}; script
The above introduces PHP learning (4)-data type, including the content, hope to be helpful to friends who are interested in PHP tutorials.