17 – Difference Between $ and $$ in PHP

0
120

Difference Between $ and $$ in PHP

This tutorial will focus on the difference between $ and $$ PHP 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.

Note:

If you have any questions about the $$ in PHP example, please feel to contact us or simply leave a comment below.

 

Facebook Comments

Leave a Reply

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