Open In App

What are the rules for naming variables in PHP?

Variables in PHP are fundamental elements used for storing data and performing operations within scripts. To maintain clarity and enhance maintainability in your codebase, it’s imperative to adhere to certain naming conventions and guidelines:

Syntax:

// Valid variable name
$myVariable; 
// Valid variable name starting with an underscore $_myVariable;
// Valid variable name using underscores $my_variable;
// Valid variable name with numbers $myVariable123;

// Valid variable name starting with an underscore and numbers $_123Variable;

// Valid variable name, but different from $myVariable (case-sensitive) $MyVariable;

Rules:

Article Tags :