30 lines
1.2 KiB
Markdown
30 lines
1.2 KiB
Markdown
---
|
|
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: In PHP variables have a default value. If a variable is not declared before you attempt to use it, its value will be NULL. It is unset. So you can't use it by writing `isset($variable)` before using it. |