Note about uninitialized variables (#19289)
* Update index.md Note about uninitialized variables. * Update index.md
This commit is contained in:
committed by
Quincy Larson
parent
598f0c4e8a
commit
107eed4a76
@ -1,31 +1,30 @@
|
|||||||
---
|
---
|
||||||
title: PHP Variables
|
title: PHP Variables
|
||||||
---
|
---
|
||||||
|
|
||||||
### PHP - Vaiables Types
|
### PHP - Vaiables Types
|
||||||
|
|
||||||
Varibles are the main way to store information in the middle way of a PHP program.
|
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`.
|
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.
|
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
|
### Variable Naming
|
||||||
|
|
||||||
Rules for naming a variable is listed below:
|
Rules for naming a variable is listed below:
|
||||||
1. Variables names must begin with a letter or underscores character.
|
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.
|
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)`.
|
3. Variable names are case-sensitive i.e. `($age and $AGE are two different variables)`.
|
||||||
|
|
||||||
### Creating (Declaring) PHP 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.
|
In PHP, a variable starts with the $ sign, followed by the name of the variable. The code snippet given below shows it.
|
||||||
|
|
||||||
``` shell
|
``` shell
|
||||||
<?php
|
<?php
|
||||||
$txt = "Hello world!";
|
$txt = "Hello world!";
|
||||||
$x = 6;
|
$x = 6;
|
||||||
$y = 10.5;
|
$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.
|
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.
|
||||||
|
|
Reference in New Issue
Block a user