In PHP, every variable starts with a dollar sign ($), followed by a letter or underscore (e.g., $userName, $_count). Variable names are case-sensitive ($age and $Age are different).
Understanding Scope
- Local Scope: Variables created inside a function only exist inside that function.
- Global Scope: Variables outside functions aren't automatically visible inside functions—you must pass them as parameters (recommended) or use
global $var;. - Static Variables: Declared with
static $count = 0;inside a function so the value is remembered between function calls.
ADVERTISEMENT