Thursday, January 31, 2008

VARIABLE



VARIABLES

A variable is the name or the object that we assign strings,integers,floats etc to.Php variables always starts with the dollar sign($).Onlike other programming language,you do not need to define the data type.A valid php variable must start with the dollar sign and the name must not start with a number or any other special character apart from alphabets and the underscore sign(_).You can define php variables like this.

VALID:

$variablename="john";
$_variablename="john";
INVALID:
variablename="john";
_variablename="john";
8variablename="john";
$variablename="john";
$8variablename="john";
Variables can be of interger values,strings,floats etc.A string must be surrounded with the " " sign like in examples above but this doesnt apply to intergers.Also,all variables and statements must end (;) sign.

OPERATORS

Php also have operators to perform arithmetic and logical statements.

Operators

+ -Addition
- -Subtration
* -Multiplication
/ -Division
% -Modulus

We all know what they are because we use them everyday of our lives.Note, the modulus operator is quite different.This operator divides two numbers and if there is a remainder,it returs it.Below are examples of this operators

Addition example

x=2;
y=x+4;

ANS:6

Subtraction example

x=2;
y=5;
z=y-x;

ANS:3

Multiplication example

x=4;
x*5;

ANS:20

Division example

x=10;
x=10/2;

ANS:5

Modulus (division remainder)

x=4;
x%3

ANS:1

Increment example(++)

x=5
x++

ANS x=6

Decrement example(++)

x=5
x--

ANS:x=4


WE WILL STOP HER FOR TODAY SO I CAN STUDY THE RESPONSE BE FOR MOVING ON.IF YOU LIKE IT,DONT HESITATE TO LET ME KNOW.

0 comments:

Design by Dzelque Blogger Templates 2007-2008