Thursday, December 1, 2011

Declare Or Define Variables In PHP

We can store values like characters,strings,integer,float values everything in a variable.In other languages we need to specify the variables type like int a or Dim a as integer etc.But in php we can store any value in a variable without specifying its type.It makes php easier than other languages.To declare a php variable we uses a $  symbol at beginning of variable name.
A variable can be defined as
$variable_name=Variables_value
Eg:
$a=1;
$a='a';
$a="a";
$a=111.11;

Sample Code to try .

<?php
$number=10;
$text="my name";
Echo $number;
Echo "<br>"; // for a new line
Echo $text;
?>

result will be
10
My name

Main Rules must obey to define variable names
Variable name shouldn't contain SPACE
$a and $A are different
You may use 0-9 a-z A-Z and _  to declare a variable name

No comments:

Post a Comment