• Skip to primary navigation
  • Skip to main content

The Programming Expert

Solving All of Your Programming Headaches

  • Home
  • Learn to Code
    • Python
    • JavaScript
  • Code Snippets
    • HTML
    • JavaScript
    • jQuery
    • PHP
    • Python
    • SAS
    • Ruby
  • About
  • Write for Us
You are here: Home / PHP / PHP Variables Are Preceded by $

PHP Variables Are Preceded by $

August 8, 2022 Leave a Comment

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.

Other Articles You'll Also Like:

  • 1.  php Rename File – Renaming Files and Directories Easily
  • 2.  Get Current Month of Date in php
  • 3.  php var_dump() Function – Print Information about Variable Type and Value
  • 4.  Using strtolower() in php to Convert String to Lowercase
  • 5.  php max – Find Maximum Value of Array in php
  • 6.  php atan2 – Find Arctangent of the Quotient of Two Numbers
  • 7.  Truncate Strings in php Using substr()
  • 8.  php array_shift() – Remove the First Element from Array
  • 9.  php Print Array – How to Print All Elements in Array
  • 10.  Replace Space with Dash in php String

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2023 · The Programming Expert · About · Privacy Policy