Things to know about PHP variables
Here are some tips which helps to you, how to declare PHP variables and used them.
In computer programming, variables are used to store information to be referenced and used by programs. They also provide a means of labeling data with a descriptive name.
In computer programming, variables are used to store information to be referenced and used by programs. They also provide a means of labeling data with a descriptive name.
Creating or Declaring Variables in PHP
In PHP, a variable starts with the dollar( $ ) sign, which followed by the name of the variable:
Example:
<?php
$txt = "Hello world!"; // output Hello world! (string)
$x = 5; // 5 (integer)
$y = 10.5; // 10.5 (float)
?>
$txt = "Hello world!"; // output Hello world! (string)
$x = 5; // 5 (integer)
$y = 10.5; // 10.5 (float)
?>
Rules to follow while declaring variables in PHP
- A variable starts with the $ sign, followed by the name of the variable
- A variable name must start with a letter or the underscore character
- A variable name cannot start with a number
- A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
- Variable names are case-sensitive ($salary and $SALARY are two different variables)
Note: Remember that PHP variable names are case-sensitive! ie above declare variable $salary and $SALARY are two different variables with different data.
Comments
Post a Comment