• 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.  Add Months to Date in php
  • 2.  php Print Array – How to Print All Elements in Array
  • 3.  How to Parse URLs with php parse_url() Function
  • 4.  php max – Find Maximum Value of Array in php
  • 5.  php Convert Degrees to Radians with php deg2rad() Function
  • 6.  Remove Specific Character from String Variable in php
  • 7.  php e – Using M_E and exp() Function to Get Euler’s Constant e
  • 8.  php var_dump() Function – Print Information about Variable Type and Value
  • 9.  php is_float() Function – Check if Variable is Float in php
  • 10.  php is_string() Function – Check if Variable is String in php

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