In PHP, 8 primitive data types are supported, including four scalar types, two composite types and two special types. This article will take you through the scalar types, composite types and special types in PHP.
PHP’s data types can be divided into three major categories, namely scalar data types, composite data types and special data types
Scalar data Type
类型 功能 boolean(布尔型) 最简单的数据类型,只有两个值:true(真) / false(假) string(字符串) 字符串是连续的字符序列 integer(整型) 整型包含所有的整数,可以是正数也可以是负数 float(浮点型) 浮点型也是用来表示数字的,与整型不同除了可以表示整数外它还可以用来表示小数和指数
Composite data type
The composite data type allows multiple data of the same type to be aggregated together and represented as an entity item. Composite data types include arrays (Array) and objects (Object)
Special data types
In PHP, there are data types used to specifically provide services or data. It does not belong to any of the above standard data types, so it is also called a special data type, mainly including NULL and resource data types.
NULL is a special data type in PHP. It has only one value, NULL, which represents a null value (the variable has no value). It should be noted that it has a different meaning from spaces
当满足下列条件时,变量的值为 NULL: 变量被指定为 NULL 值; 变量在没有被赋值前,默认值为 NULL; 使用 unset() 函数删除一个变量后,这个变量值也为 NULL。
Resource
Resource is also a special data type in PHP. It mainly describes a PHP extended resource, such as a database query (Query), an open file handle (fopen) or a database connection (Database Connection), and character stream (stream) and other extended types.
But we cannot directly operate this variable type and can only use it through special functions.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of A brief discussion of scalar types, composite types and special types in PHP. For more information, please follow other related articles on the PHP Chinese website!