Data Types
Explore different data types in PHP, such as strings, integers, and arrays.
Data Types is a free PHP Academy lesson on CoddyKit — lesson 2 of 5. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the PHP Academy learning path, one of 5 lessons in the course, and your progress syncs across the web and the CoddyKit app.
1
Data Types
Welcome to a deeper dive into PHP! In this lesson, you’ll learn about PHP’s data types, which determine the kind of data a variable can store. Understanding data types is essential for writing effective PHP programs. Let’s begin!

2
What Are Data Types?
Data types specify the kind of data that a variable can hold. PHP is a dynamically typed language, meaning variables can change their type during execution.
Example:
Key Point: PHP automatically determines the data type of a variable based on its value.
<?php
$value = 42; // Integer
echo $value;
$value = "Hello"; // Now a String
echo $value;
?>
3
PHP Data Types
PHP supports the following data types:
- String: A sequence of characters.
- Integer: Whole numbers.
- Float: Decimal numbers.
- Boolean: True or false values.
- Array: A collection of values.
- Object: An instance of a class.
- NULL: Represents a variable with no value.
- Resource: Special variables holding references to external resources.
Let’s explore these in detail.
4
Strings
A string is a sequence of characters, enclosed in single (') or double (") quotes. Example:
Key Point: Use double quotes when you need to include variables in the string directly.
<?php
$greeting = "Hello, World!";
echo $greeting; // Outputs: Hello, World!
?>
5
Numbers
PHP supports two types of numbers:
- Integer: Whole numbers.
- Float: Numbers with decimals.
Example:
<?php
$integer = 42;
$float = 3.14;
echo "Integer: $integer, Float: $float";
?>
6
Booleans
A boolean represents one of two values: true or false. Booleans are often used in conditional statements. Example:
<?php
$isLoggedIn = true;
if ($isLoggedIn) {
echo "Welcome back!";
} else {
echo "Please log in.";
}
?>
7
Arrays
An array is a collection of values stored in a single variable. Arrays can hold multiple types of data. Example:
Key Point: Arrays are zero-indexed, meaning the first element has an index of 0.
<?php
$colors = ["Red", "Green", "Blue"];
echo $colors[0]; // Outputs: Red
?>
8
Special Types
PHP has some special data types:
- NULL: A variable with no value.
- Resource: A reference to an external resource, such as a database connection.
Example:
Tip: Use var_dump() to inspect the type and value of a variable.
<?php
$empty = NULL;
echo $empty; // Outputs nothing
?>
9
<?php
$value = "42";
echo gettype($value);
?>
10
Great Job!
Congratulations! You’ve explored PHP’s data types, including strings, numbers, booleans, arrays, and special types like NULL. Understanding data types is essential for writing efficient and bug-free code. In the next lesson, we’ll explore operators and how to perform various operations in PHP. Let’s keep coding!

Frequently asked questions
Is the “Data Types” lesson free?
Yes — the full text of “Data Types” is free to read here on the web, and the PHP Academy course includes 5 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the PHP Academy course, upgrade to CoddyKit PRO.
What will I learn in “Data Types”?
Explore different data types in PHP, such as strings, integers, and arrays. You practise PHP Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start PHP Academy?
No prior experience is required. PHP Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 5, so you can start here or from the beginning and move at your own pace.
How long does the “Data Types” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this PHP Academy lesson?
Yes. Every PHP Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.