PHP Variable

PHP Variables

PHP Variables are used to store information.

<?php
$a=10;
$b=5;
$c=$a+$b;
echo $c;
?>

There are some important rules before assign variable. Keep in mind.

$                    A PHP every variable starts with $ sign, followed by the name of the variable.
123                A PHP variable name cannot start with a number.
Abc, _           A PHP variable name must start with a letter or the underscore character.
A-z, 0-9, _     A PHP variable can name only with alpha-numeric characters and underscores.
$a and $A     A PHP Variable names are case sensitive.


PHP Loosely Typed Language

In the above examples have you noticed that we did not have to declare PHP which data type the variable is, a single variable may contain any type of data int, float, string etc.



PHP convert automatically its variable to the correct data type, unlike other programming languages C, C++, Java we do not need to declare its data type.

0 comments:

Post a Comment