Saturday, November 13, 2004

Fun with Operations

I hope you have used a calculator before ... If not, go buy one and work on it ... it makes the following explanation much clearer ...

Maths Operation

Add: +
Subtract: -
Divide: /
Multiply: * (not 'x' as on a calculator;)
Modulus: %
Assignment: =

String Operation

Concatenate: . (yes ... it is a 'dot')

Shortforms

Add and Assign: +=
Subtract and Assign: -=
Divide and Assign: /=
Multiply and Assign: *=
Modulus and Assign: %=
Concatenate and Assign: .=

Comparison Operation

Equal: ==
Not equal: !=
Equal and same datatype: ===
Greater: >
Greater than or equal: >=
Less than: <
Less than or equal: <=

Logical Operations

OR: ||
AND: &&
NOT: !
XOR: xor (... ONLY IF either left or right operand is true.)

Pre-Increment: ++$var
Pre-Decrement: --$var
Post-Increment: $var++
Post-Decrement: $var--

eg.

<?php

$left = true;
$right = false;

$result = ($left xor $right);

print($result);

?>

What will be the result? Try it out! (Result is "1".)

0 Comments:

Post a Comment

<< Home