PHP supports these data types:
string,int,float,boolarray,objectnullandresource
var_dump() shows a value's type and contents; gettype() returns the type name. Cast with (int), (string), (float), (bool).
Strings, integers, floats, booleans, arrays, objects and null.
✍️ 2 exercises in this lessonPHP supports these data types:
string, int, float, boolarray, objectnull and resourcevar_dump() shows a value's type and contents; gettype() returns the type name. Cast with (int), (string), (float), (bool).
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
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");
string(5) "Hello"
int(42)
float(3.14)
bool(true)
array(2) { [0]=> int(1) [1]=> int(2) }
NULL
integer
Check what you learned in “PHP Data Types”.
Show the type and value of a variable.
($price);
What is the type of 3.14 in PHP?
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