17 – Difference Between PHP $$ and $ Variables

0
86

Difference Between PHP $$ and $ Variables

This tutorial will focus on the difference between PHP $$ and $ Variables To start with, let’s review first what is PHP Variables.

PHP Variable plays a vital role in PHP programming. It allows you to store information in computer memory.

To declare a PHP variable, it starts with a dollar sign($) like as shown in the syntax below

PHP Variable Syntax:

$$ Meaning in PHP(Double Dollar Variable

The PHP $$ (double dollar) variable is a reference variable that stores the value which is accessible by using $ Symbol(Single Dollar) variable value

They call it sometimes as a variable variable name. Wherein the variable name can be set and used dynamically.

Below examples illustrate the use of $ and $$ in PHP

Output Will Be:
PHP

Here’s the $$ in PHP Example

Output Will Be:

PHP
Programming!
Programming!

Another Complex Example of $$ in PHP

Output Will Be:

PHP
Programming
Is Fun!
Is Fun!

We will discuss what we have in the above code using PHP Double dollar and Dollar Variables

  1. First, we declare and initialize the variable.
  2. Then, reference the variable
  3. Next, we use the double reference variable
  4. Finally, we display the value of the variable.
  5. Lastly, we display a double reference.

Facebook Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.