Files
freeCodeCamp/client/src/pages/guide/english/php/PHP Variables/index.md

32 lines
1.1 KiB
Markdown
Raw Normal View History

---
title: PHP Variables
---
### PHP - Vaiables Types
Varibles are the main way to store information in the middle way of a PHP program.
All variables in PHP are donated with a leading dollar sign like `$variable_name`.
Variables are assigned with the `= operator` , with the variable on the left-hand side and the expression to be evaluated on the right.
### Variable Naming
Rules for naming a variable is listed below:
1. Variables names must begin with a letter or underscores character.
2. A variable name can consist of numbers, letters, underscores but you cannot use characters like `+ , - , % , ( , ) . &` in its name.
3. Variable names are case-sensitive i.e. `($age and $AGE are two different variables)`.
### Creating (Declaring) PHP Variables
In PHP, a variable starts with the $ sign, followed by the name of the variable. The code snippet given below shows it.
``` shell
<?php
$txt = "Hello world!";
$x = 6;
$y = 10.5;
?>
```
Variable lifecycle: Before a variable is used, it has no existence. It is unset. So you can't use it by writing isset($variable) before using it.