PHP 

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-

<?php
$name=’Hello world’;
$number=20;
$float=10.2;
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-

<?php
$name=’world’;
$title=’Hello’;
echo $title.’ ‘. $name;
?>

Adding two number variable such as-

<?php
$first=10;
$second=5;
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 *

error: