What is a variable?
As we have studied in Algebra that a variable is used to hold a value which can be further used in various formulas for performing calculations.
Examples x=10, speed=100
The words "x" and "speed" are therefore called variables and can be used in various expressions.
Rules For Naming PHP Variables
As we have studied in Algebra that a variable is used to hold a value which can be further used in various formulas for performing calculations.
Examples x=10, speed=100
The words "x" and "speed" are therefore called variables and can be used in various expressions.
Rules For Naming PHP Variables
- A variable in PHP always begins with a $ sign and then the name of the variable.
- After $ sign there must be a letter or an underscore character.
- Spaces are not allowed in variable names.
- In PHP variable names are case sensitive eg: SUM and sum are considered as two different variables.
- A variable name should only contain alphanumeric characters (A-Z, a-z, 0-9) and in place of spaces underscore should be used.
Variable Declaration in PHP
Variables are created in PHP starting with a $ sign as follows
Example:
$firstname="John";
Example:
<?php
$firstname="John";
$lastname="Travolta";
$city="California";
echo $firstname;
echo $lastname;
echo $city;
?>
PHP is very Loosely Packed Language
In PHP a variable does not need to be declared before assigning a value to it. PHP automatically converts the variable to the required data type according to the value assigned. Whereas in other languages like C, C++ you have to declare a variable by specifying the type of data it will hold and then the value is assigned to that variable.
Scope Of Variables
Scope defines the accessibility or availability of a variable at different places in a program.
Scope of variables read more...
Example:
$firstname="John";
Example:
<?php
$firstname="John";
$lastname="Travolta";
$city="California";
echo $firstname;
echo $lastname;
echo $city;
?>
PHP is very Loosely Packed Language
In PHP a variable does not need to be declared before assigning a value to it. PHP automatically converts the variable to the required data type according to the value assigned. Whereas in other languages like C, C++ you have to declare a variable by specifying the type of data it will hold and then the value is assigned to that variable.
Scope Of Variables
Scope defines the accessibility or availability of a variable at different places in a program.
Scope of variables read more...
No comments:
Post a Comment