PHP Variables Example

Declare PHP variables and work with strings, integers, floats and booleans. Edit the code below and press Run to execute it with real PHP in your browser.

Code Editor
Output
Name: John
Age: 25
Price: $19.99
Active: Yes
double

How this variables example works

PHP variables start with $ and need no type declaration: the type comes from the value. Double-quoted strings interpolate variables, so "Age: $age" prints the value; a literal dollar sign is escaped as \$. gettype() reports "double" for floats for historical reasons.

Inspect types with var_dump()

<?php
var_dump("John", 25, 19.99, true, null);

Output:

string(4) "John"
int(25)
float(19.99)
bool(true)
NULL