In PHP, when you create a new variable or go to use an existing variable, you need to put a dollar sign $ before the variable name.

$a = 1
$b = 2
$c = $a + $b

Depending on which programming language you use, there can be different conventions around how you can define and use variables.

In PHP, variables are preceded by $. When you create a new variable or go to use an existing variable, you need to put a dollar sign $ before the variable name.

Below shows you an example of how PHP variables are preceded by $.

$a = 1
$b = 2
$c = $a + $b

Why are PHP Variables Preceded by $?

You might ask yourself, why are PHP variables preceded by $ and not by another character or nothing?

PHP variables start with the dollar sign symbol because PHP was based on the Perl programming language which uses $ to start variables.

The Perl programming language used $ because the creator was inspired from shell scripting.

One last point is that you may notice that many PHP methods are similar if you have experience with shell scripting and since the creators of PHP were inspired by Perl and shell scripting.

Hopefully this article has been useful for you to learn that PHP variables are preceded by dollar signs.

Categorized in:

PHP,

Last Update: March 12, 2024