• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • Ruby
  • About
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 preg_match_all – Get All Matches of Pattern in String
  • 2.  php property_exists() – Check if Property Exists in Class or Object
  • 3.  php unset – How to Destroy Variables in php
  • 4.  Get Current Month of Date in php
  • 5.  php is_array() Function – Check if Variable is Array in php
  • 6.  php array_key_exists() Function – Check if Key Exists in Array
  • 7.  preg_replace php – Use Regex to Search and Replace
  • 8.  Get User Agent in php with $_SERVER[‘HTTP_USER_AGENT’]
  • 9.  Truncate Strings in php Using substr()
  • 10.  Remove String from String in php with str_replace()

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 *

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

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

x