PHP Variables

For storing information in PHP, use variables. Variables are also known as containers.  For example, easily store numeric values such as 10, 20, 30, etc in variables. With that, also store any string in variables as shown in the first PHP program, etc. Let’s learn about the syntax,


Variable in PHP begins with a $ sign. After that, type the variable name. Here’s an example:

Here’s the output,

PHP Variables

As shown above, the following can be seen, with three variables,

  • Variable $a holds the value 10
  • Variable $b holds the value 20
  • Variable $result holds the value; We have two values, as shown above.
  • Any text inside quotes is a string.

PHP Variable Rules

Some rules are defined for the usage of variables in PHP. Let’s see them one by one with examples:

  • A variable name must start with a letter or the underscore character.
    For example, $dept
  • A variable starts with the $ sign, followed by the name of the variable.
    For example, $result
  • A variable name cannot start with a number.
    For example, “2value” isn’t the correct way to name a variable.
  • A variable name can only contain alpha-numeric characters and underscores.
    For example, result_rank, value1
  • Variable names are case-sensitive.
    For example, $result and $RESULT are two different variables.

PHP variable naming conventions

PHP Tutorial
PHP Arrays
Studyopedia Editorial Staff
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading