You are here: Home / Topics / Rules for naming a PHP variable

Rules for naming a PHP variable

Filed under: PHP on 2022-10-08 08:40:21

The following two rules are needed to be followed while naming a PHP variable:

  • A variable must start with a dollar symbol, followed by the variable name. For example: $price=100; where price is a variable name.
  • Variable names must begin with a letter or underscore.
  • A variable name can consist of letters, numbers, or underscores. But you cannot use characters like + , – , % , & etc.
  • A PHP variable name cannot contain spaces.
  • PHP variables are case-sensitive. So $NAME and $name both are treated as different variables.

About Author:
S
Shivam     View Profile
Hi, it's Shivam and this website is very good.