PHP Variables
Variables in PHP start with $ followed by the name. They are dynamically typed.
Basic Syntax
$name = "John"; // String
$age = 25; // Integer
$price = 19.99; // Float
$is_active = true; // Boolean
Naming Rules
- Start with
$followed by a letter or underscore - Case-sensitive (
$name≠$Name) - Use descriptive names in camelCase or snake_case
Variable Scope
- Global — Declared outside functions
- Local — Declared inside functions
- Static — Retains value between function calls