Friday, 3 July 2015

PHP Variables

A variable is used to store the information. In php variable is declare by $ symbol.

Variables in PHP

  • Variables are used for storing a values, like text string, numbers or arrays.
  • When a variable is declare, it can be used over and over again in your scripts.
  • Variable does not need to be declare before adding a value to it.
  • In a strongly typed programing language, you have to declare the type and name of the variable before using it.
  • The correct way of declaring a variable in PHP:
$var_name = value;

  • New php programs often forget the $ sign at the beginning of the variable.In that case it will not work.
  • Let’s try creating a variable containing a string, and a variable containing a number:
<?php$txt=”Hello World”;$x=16;?>

<?php
$x=4;
$y=20;function calci()
{
$[‘y’]=$[‘x’]*$[‘y’];
}calci();
echo $y; // outputs 80
?>

No comments:

Post a Comment