Variables in PHP
Variable Name Guidelines
- Must start with alphabetical character
- Variable names are case-sensitive
- can't contain any periods or type-declaration characters
- must be unique within the same scope
- must be 255 characters or less
- Variable must
begin with a letter or the underscore character
How to use variables?
In
php, variable starts with $ symbol. for example:
$age = 5;
$name = "Chris";
<?PHP
$name=”my name is mark”;
print $name;
?>
$name=”my name is mark”;
print $name;
?>
In this example we have defined two variable name, age, name has string value “mark” but age has numeric value 35, The output will display as below:
my name is mark
Another Example of PHP
<?php
$value1=35;
$value2=88;
$result=$value1+$value2;
print "Result is";
print $result;
?>
$value1=35;
$value2=88;
$result=$value1+$value2;
print "Result is";
print $result;
?>
Output
Result is 123