PHP Data Types

Strings, integers, floats, booleans, arrays, objects and null.

✍️ 2 exercises in this lesson

PHP supports these data types:

  • string, int, float, bool
  • array, object
  • null and resource

var_dump() shows a value's type and contents; gettype() returns the type name. Cast with (int), (string), (float), (bool).

Key Takeaways: PHP Data Types

Mastering PHP Data Types helps you write clean and reliable PHP code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

PHP Data Types Code Example

PHP
<?php
var_dump("Hello");
var_dump(42);
var_dump(3.14);
var_dump(true);
var_dump([1, 2]);
var_dump(null);
echo gettype((int) "15 apples");
Output
string(5) "Hello"
int(42)
float(3.14)
bool(true)
array(2) { [0]=> int(1) [1]=> int(2) }
NULL
integer
Run this example on your own computer. The "Get Started" lesson shows how to set it up.

PHP Data Types Practice Exercises

Check what you learned in “PHP Data Types”.

/ 2 solved
Fill in the blank

Show the type and value of a variable.

($price);
✓ Correct! Not quite. Try again.
Multiple choice

What is the type of 3.14 in PHP?

✓ Correct! Not quite. Try again.
to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services