
PHP data types(8 basic data and some pseudo types)
There are 8 basic data types and some pseudo types in PHP. The basic data types are divided into scalar, composite and special types. Compared with C#, there are a lot less types, but it can also achieve many functions, and it is no worse than other languages.
PHP data types(8 basic data and some pseudo types)
One, basic types
1. Scalar type(4 types)
1) integer
The integer represents an integer, ranging from -2,147,483,647 to 2,147,483,648. The word length is platform-dependent. 32-bit signed integers. PHP does not support unsigned integers.
2) boolean
The boolean is the simplest type, used to express true and false values, it can be TRUE or FALSE, both are not case sensitive.
3) float(floating point type, also called double)
The float represents a floating-point number (also called double-precision number or real number), the word length is platform-dependent, usually the maximum value is 1.8e308, and has a precision of 14 decimal digits(64-bit IEEE format).
4) string
The string represents a collection of a series of characters, one character occupies one byte, and one byte can only have 256 different variations, which makes PHP unable to natively support Unicode.
2. composite type(2 types)
1) array
An array is essentially an ordered map in PHP, which is the type associates values ??with keys(key-value pairs). It has been optimized in many ways, so it can be regarded as a real array, or a list(vector), a hash table (an implementation of mapping), a collection, a dictionary, a stack, a queue and more possibilities. Arrays can be nested, that is, the value of an element can also be another array; in addition, tree structure and multi-dimensional arrays are also allowed.
definition form:
array( key => value
, ...
) // The key can be an integer or a string, and the value can be any type of value.
2) object
The object is used to instantiate a class, mainly through new.
3. Special type
1) resource
The resource is a special variable used to save a reference to an external resource. It is created and used by a special function.
2) NULL
The NULL means that a variable has no value, it may not have been assigned, it has been assigned a value of NULL, or it has been unset().
Two, pseudo type
1. mixed
The mixed means that a parameter can accept many different(but not necessarily all) types.
2. number
The number indicates that a parameter can be integer or float.
3. callback
The callback function can be not only a simple function, but also an object method(including static class methods).