PHP - Introduction Data Types

Introduction

All data in PHP variables fall into one of eight basic categories, known as data types.

A variable's data type determines what operations can be carried out on the variable's data, as well as the amount of memory needed to hold the data.

Scalar data types

PHP supports four scalar data types.

Scalar data means data that contains only a single value.

Here's a list of them, including examples:

Scalar Data Type Description Example
Integer A whole number 15
Float A floating - point number 8.23
StringA series of characters "Hello, world!"
Boolean Represents either true or false true

Compound types

PHP supports two compound types.

Compound data is data that can contain more than one value.

The following table describes PHP's compound types:

Compound Data TypeDescription
Array An ordered map (contains names or numbers mapped to values)
ObjectA type that may contain properties and methods

PHP supports two special data types

Special Data TypeDescription
Resource Contains a reference to an external resource, such as a file or database
Null May only contain null as a value

Related Topic