PHP supports 8 basic data types.
Four scalar types:
- boolean (Boolean type)
- integer (integer type)
- float (Floating point type, also called double)
- string (string) UL>
- array (array)
- object (object)
- resource (resource)
- NULL (NULL)
-
the Boolean value
FALSE
itself - the integervalue 0 (zero)
- the floating point value 0.0 (zero)
- Empty String, and String "0"
- array not containing any elements
- Object that does not include any member variables (only applicable to PHP 4.0)
- Special type NULL (including variables that have not been set)
- SimpleXML object generated from an XML document without any tags (tags)
Two composite types:
Finally there are two special types:
booleanData type:
The value can only be True or False. When other types are converted to boolean types, the following values are considered FALSE
:
All other values are considered TRUE
(including any resource).
integer data type:
Integer values can be represented in decimal, hexadecimal or octal notation, preceded by an optional symbol (- or ).
Octal means that the number must be preceded by 0 (zero), and hexadecimal means that the number must be preceded by 0x.
The word size of integers is platform-dependent, although the usual maximum is about two billion (32-bit signed). PHP does not support unsigned integers. Integer The word length of the value can be represented by the constant PHP_INT_SIZE
, since PHP 4.4.0 and PHP 5.0 After .5, the maximum value can be represented by the constant PHP_INT_MAX
.
If a given number exceeds the range of integer, it will be interpreted as float. Similarly, if the result of the operation exceeds the range of integer, float.
There is no integer division operator in PHP. 1/2 produces float 0.5. You can always discard the fractional part, or use the round() function.
To explicitly convert a value to integer , use (int) or (integer) to cast. In most cases, however, casting is not necessary, because when an operator, function, or flow control requires a integer parameter, the value will be converted automatically. You can also use the function intval() to convert a value to an integer type.
Converting from Boolean, FALSE
will produce 0 (zero), TRUE
Will produce 1 (one).
Convert from Floating Point. When converting from floating point to integer, convert to Zerorounding. If the floating point number is outside the integer range (usually /- 2.15e 9 = 2^31), the result is undefined because there is not enough precision for the floating point number to give an exact integer result. There is no warning in this case, not even any notification!
float data type
The word size of floating-point numbers is platform-dependent, although typically the maximum value is 1.8e308 with a precision of 14 decimal digits (64-bit IEEE format).
Apparently simple decimal fractions like 0.1 or 0.7 cannot be converted to the internal binary format without losing a little precision. This can lead to confusing results: for example, floor((0.1 0.7)*10) will usually return 7 instead of the expected 8 , because the internal representation of the result is actually similar to 7.9.
This is related to the fact that it is impossible to express certain decimal fractions accurately with a finite number of digits. For example, 1/3 in decimal becomes 0.3.
So never trust that a floating-point number result is accurate to the last digit, and never compare two floating-point numbers to see if they are equal. If you really need higher precision, you should use arbitrary precision math functions Or gmp function.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Zend Studio 13.0.1
Powerful PHP integrated development environment

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
