PHP Data Types
Summary: Data Types defines the type of data a variable can store. PHP allows eight different types of data types. All of them are discussed below. The first five are called simple data types and the last three are compound data types:
Data Types defines the type of data a variable can store. PHP allows eight different types of data types. All of them are discussed below. The first five are called simple data types and the last three are compound data types:
- Integers − are whole numbers, without a decimal point, like 1012.
- Doubles − are floating-point numbers, like 10.12or 9.1.
- Booleans − have only two possible values either true or false.
- NULL − is a special type that only has one value: NULL.
- Strings − are sequences of characters, like 'PHP supports string operations.'
- Arrays − are named and indexed collections of other values.
- Objects − are instances of programmer-defined classes, which can package up both other kinds of values and functions that are specific to the class.
- Resources − are special variables that hold references to resources external to PHP (such as database connections).
The first five are simple types, and the next two (arrays and objects) are compound - the compound types can package up other arbitrary values of arbitrary type, whereas the simple types cannot.
We will explain only simple data types in these chapters. Array and Objects will be explained separately
PHP Data Type Function
| Function | Purpose |
| is_bool() | Test if a variable holds a boolean value |
| is_numeric() | Test if a variable holds a numeric value |
| is_int() | Test if a variable holds an integer |
| is_float() | Test if a variable holds a floating-point value |
| is_string() | Test if a variable holds a string value |
| is_null() | Test if a variable holds a Null value |
| is_array() | Test if a variable holds is an array |
| is_object() | Test if a variable holds is an object |
