Variable:
Variable means whose value can be changed.
Variable contains value which is stored in
memory and holds some space.
In PHP, a variable starts with the $
sign, followed by the name of the variable.
2 steps to use variables
· Variable
Declaration
· Variable
Initialization
Variable Declaration:
Syntax:
$variable_name;
Eg 1:
$x;
$x is the variable name.
Eg 2:
$y;
$ch;
$name;
$y;
$ch;
$name;
Where
$y,$ch and $name are the variables.
Variable Initialization:
Syntax:
$variable_name=value;
Eg 1:
$x=89;
Where $x is the variable name and 89 is the
value which assigned to $x.
Eg 2:
$y=78.90;
$ch=’A’;
$name=”LearningPoint92”;
Rules for defining variables
It can have alphabets, digits and underscore.
A variable name should start with alphabet
and underscore only. It can't start with digit.
No white space is allowed within variable
name.
A variable name cannot be any reserved word
or keyword e.g. double, float etc.
Example:
<?php
$name="Dipak";
$age=78;
$marks=12.35;
echo "Name is: $name
<br/>";
echo "Age is: $age
<br/>";
echo "Marks is:
$marks<br/>";
?>
Output:
Name is:Dipak
Age is:78
Marks is:12.35
No comments:
Post a Comment