Home > Backend Development > PHP Tutorial > Study Notes on PHP Data Types_PHP Tutorial

Study Notes on PHP Data Types_PHP Tutorial

WBOY
Release: 2016-07-13 10:50:34
Original
752 people have browsed it

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:

================================================== ====================================== array
The code is as follows
 代码如下 复制代码
$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)
$foo = 1 + “bob3″; // $foo is integer (1)
$foo = 1 + “10 Small Pigs”; // $foo is integer (11)
$foo = 4 + “10.2 Little Piggies”; // $foo is float (14.2)
$foo = “10.0 pigs ” + 1; // $foo is float (11)
$foo = “10.0 pigs ” + 1.0; // $foo is float (11)
?>
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)
$foo = 1 + “bob3″; // $foo is integer (1)
$foo = 1 + “10 Small Pigs”; // $foo is integer (11)
$foo = 4 + “10.2 Little Piggies”; // $foo is float (14.2)
$foo = “10.0 pigs ” + 1; // $foo is float (11)
$foo = “10.0 pigs ” + 1.0; // $foo is float (11)
?>


An array in PHP is actually an ordered graph. A graph is a type that maps values ​​to keys. Utility functions: The unset() function allows unsetting a key in an array. Be aware that the array will not be reindexed. ================================================== ================================= NULL The special NULL value indicates that a variable has no value. The only possible value of type NULL is NULL. Note: The NULL type was introduced in PHP 4. A variable is considered NULL in the following situations: is assigned the value NULL. has not been assigned a value yet. is unset().

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632623.htmlTechArticleThere are 8 scalar types in php, including string (string), integer (integer), float (floating point type, also called double), boolean (Boolean) and composite types and resource (resource), NULL (empty), next...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template