Variables in PHP store data that can be used and manipulated throughout your script. All variables in PHP start with a $ sign followed by the variable name.
Variable Rules
- Must start with
$followed by a letter or underscore - Can contain letters, numbers, and underscores
- Are case-sensitive (
$nameand$Nameare different) - Do not need to be declared before use
PHP Data Types
- String — Text:
$name = "SukhNexus"; - Integer — Whole numbers:
$age = 25; - Float — Decimal numbers:
$price = 99.99; - Boolean — True or false:
$active = true; - Array — Collection of values:
$colors = ["red", "green"]; - NULL — No value:
$item = null;
Type Juggling
PHP is loosely typed — a variable can change its type automatically. Use gettype() to check the type and var_dump() to debug.