PHP variable simple define with the $ sign, followed by the name of the variable and you can use this sign for define all types of variable. such as-

$name=’Hello world’;
echo $name;
echo $number;
echo $float;

PHP is a Loosely Typed Language and notice that above example we did not have to mention PHP which data type the variable is.

PHP automatically converts the variable to the correct data type by its define value.

In other languages such as C, C++, and Java, the programmer must declare the name and type of the variable before using it.

Rules Of Variables:

  • A variables name must be start with a letter or the underscore character.
  • A variables name cannot start with a number.
  • A variables name can only contain alpha-numeric characters and underscores.
  • Variable names are case-sensitive ($name and $NAME are two different variables

Concatenate the two string variable such as-

echo $title.’ ‘. $name;

Adding two number variable such as-

echo $ first + $ second;

News Reporter
IT Software and web development, Core PHP, JavaScript, JQuery, HTML, CSS, CakePHP, Angularjs, Codeigniter etc.

Leave a Reply

Your email address will not be published. Required fields are marked *