0
0
PhpConceptBeginner · 3 min read

What is $ Sign in PHP: Meaning and Usage Explained

In PHP, the $ sign is used to declare and access variables. It tells PHP that the following name is a variable holding data like numbers or text.
⚙️

How It Works

The $ sign in PHP acts like a label that marks a word as a variable. Think of it as a name tag you put on a box to remember what's inside. Whenever you want to store or use information, you give it a name with $ in front, so PHP knows you are talking about a variable.

For example, if you want to remember someone's age, you write $age. PHP then knows $age holds a value, like 25. This is different from normal words because the $ sign tells PHP to look for the stored value, not just treat it as text.

💻

Example

This example shows how to create a variable with $, assign a value, and print it.

php
<?php
$greeting = "Hello, friend!";
echo $greeting;
?>
Output
Hello, friend!
🎯

When to Use

Use the $ sign whenever you want to store or work with data in PHP. Variables let you keep information like names, numbers, or results from calculations so you can use them later in your program.

For example, if you build a website that asks for a user's name, you store that name in a variable like $username to greet them personally. Or if you calculate a total price, you save it in $total to show or use in other parts of your code.

Key Points

  • The $ sign is always placed before variable names in PHP.
  • Variable names start with a letter or underscore after the $ sign.
  • Variables store data like text, numbers, or more complex information.
  • Using $ helps PHP know you mean a variable, not just a word.

Key Takeaways

The $ sign marks a variable in PHP, telling the language to store or access data.
Always use $ before variable names to work with values like text or numbers.
Variables help keep and reuse information throughout your PHP program.
Variable names must start with a letter or underscore after the $ sign.
Using $ correctly is essential for PHP to understand your code.