Friday, 7 August 2015

PHP Variables :-

Variables are like "containers" for storing information.

In PHP, a variable starts with the"$" sign, followed by the name of the variable.

Some Points to be remembered :-
  • A variable name must start with a letter or the underscore character.
  • A variable name,declared in PHP, cannot start with a number.
  • A variable name can only contain alpha-numeric characters & underscores(a-z, A-Z, 0-9 and etc).
  • Variable names are case-sensitive. ($name and $NAME are totally different in PHP).

A sample example to illustrate the concept of PHP variable :-

variable.php:-
<!DOCTYPE html>
<html>
<body align="center">

<?php
$a = "Hi Everyone";                 //Assigning String Value
$b = 1;                                         //Assigning Integer Value
$c = 20.5;                                    //Assigning Float Value

echo $a;
echo "<br>";
echo $b;
echo "<br>";
echo $c;
?>

</body>
</html>


Screenshot:-


Here, "<br>" tag is used to display the text in the next line.
PHP statements end with a semicolon ";".

No comments:

Post a Comment