Skip to content

PHP Snippets: Data Types

PHPThis post is part of the PHP Snippets series where I will be covering the basics of developing in PHP.

PHP supports a number of data types which are used to store different kinds of values; understanding data types is important as they affect how values are stored, compared, and manipulated.

The main scalar data types in PHP are:

String — a sequence of characters, enclosed in single or double quotes:

$fruit = 'apples';

Integer — a whole number, positive or negative, without a decimal point:

$count = 42;
$temperature = -5;

Float — a number with a decimal point, also referred to as a double:

$price = 9.99;

Boolean — a value that is either true or false, commonly used in conditional logic:

$inStock = true;
$isExpired = false;

In addition to scalar types, PHP also supports the following:

Null — a variable with no value assigned, or one explicitly set to null:

$value = null;

Array — a variable that holds multiple values (covered in more detail in a later post in this series).

Object — an instance of a class, used in object-oriented programming.

You can check the data type of any variable using the gettype() function, or use var_dump() to output both the type and the value together:

$price = 9.99;
echo gettype($price);   // outputs: double
var_dump($price);       // outputs: float(9.99)

If there is a topic which fits the typical ones of this site, which you would like to see me write about, please use the form, below, to submit your idea.

Ian Grieve originally posted this article on 24 July 2026 at 11:00 AM.

Leave a Reply