echo "Perform addition: 2 + 4 = ".$addition; echo "Perform subtraction:
6 - 2 = ".$subtraction; echo
"Perform multiplication: 5 * 3 = ".$multiplication; echo "Perform division:
15 / 3 = ".$division; echo "Perform modulus: 5
% 2 = " . $modulus . "[ Modulus is the remainder after the division
operation has been performed.In this case it was 5 / 2, which has a
remainder of 1].";
?>
Display:
Perform addition: 2 + 4 = 6 Perform
subtraction: 6 - 2 = 4 Perform multiplication: 5 * 3 = 15 Perform
division: 15 / 3 = 5 Perform modulus: 5 % 2 = 1 [Modulus is
the remainder after the division operation has been performed. In this
case it was 5 / 2, which has a remainder of 1.]
Comparison Operators
Comparison
operators are used to check the relationship between variables
and/or values.
Comparison operators are
used inside conditional statements and
evaluate to either true or false.
Important
comparison operators of PHP are:-
Operator
English
Example
Result
==
Equal To
$x
== $y
false
!=
Not Equal To
$x != $y
true
<
Less Than
$x < $y
true
>
Greater Than
$x > $y
false
<=
Less Than or
Equal To
$x <= $y
true
>=
Greater Than or
Equal To
$x >= $y
false
String Operators
There
is only one string operator. ["." the period]
It
is used to add two strings together,
or more technically, the period is the concatenation operator for
strings.
In programming, various
increasing or decreasing counters are used.
Say you
want a counter that increase by 1,
$number
= $number + 1;
However,
there is a
shorthand for doing this.[combination
assignment/arithmetic operator that would accomplish the same
task]
$number +=
1;
Here are some examples
of other
common shorthand operators. In general,
"+=" and "-=" are the most widely used combination operators.
Operator
English
Example
Equivalent
Operation
+=
Plus
Equals
$x += 2;
$x = $x + 2;
-=
Minus Equals
$x -= 4;
$x = $x - 4;
*=
Multiply Equals
$x *= 3;
$x = $x * 3;
/=
Divide Equals
$x /= 2;
$x = $x / 2;
%=
Modulo Equals
$x %= 5;
$x = $x % 5;
.=
Concatenate Equals
$my_str.= "hello";
$my_str = $my_str .
"hello";
Pre/Post-Increment &
Pre/Post-Decrement
There is an even shorter way
for adding 1
or subtracting 1 from a variable.
To add one to a variable or "increment" use the "++" operator:
$x++;
Which is
equivalent to $x += 1; or $x = $x + 1;
To subtract 1 from a variable, or "decrement" use the "--"
operator:
$x--;
Which is
equivalent to $x -= 1; or $x = $x - 1;
In
addition to this you
can specify whether you want the increment to be:-
Before code is being executed.
After the line has executed.
Example code below will display the difference.
PHP Code:
<?php
$x
= 4; echo "The value of x with post-plusplus = " . $x++;
echo "The value of x after the post-plusplus is " . $x;
$x
= 4; echo "The value of x with with pre-plusplus = " . ++$x;
echo "The value of x after the pre-plusplus is " . $x;
?>
Display:
The
value of x with post-plusplus = 4 The
value of x after the post-plusplus is = 5 The value of x with
with pre-plusplus = 5 The value of x after the pre-plusplus is
= 5
The value of $x++ is not
reflected in the echoed text because the variable is not incremented
until after the line of code is executed.
But,
with the
pre-increment "++$x" the variable does reflect the addition immediately.
Note For more detail please see Php Manual at http://www.php.net
echo "Perform addition: 2 + 4 = ".$addition; echo "Perform subtraction:
6 - 2 = ".$subtraction; echo
"Perform multiplication: 5 * 3 = ".$multiplication; echo "Perform division:
15 / 3 = ".$division; echo "Perform modulus: 5
% 2 = " . $modulus . "[ Modulus is the remainder after the division
operation has been performed.In this case it was 5 / 2, which has a
remainder of 1].";
?>
Display:
Perform addition: 2 + 4 = 6 Perform
subtraction: 6 - 2 = 4 Perform multiplication: 5 * 3 = 15 Perform
division: 15 / 3 = 5 Perform modulus: 5 % 2 = 1 [Modulus is
the remainder after the division operation has been performed. In this
case it was 5 / 2, which has a remainder of 1.]
$x
= 4; echo "The value of x with post-plusplus = " . $x++;
echo "The value of x after the post-plusplus is " . $x;
$x
= 4; echo "The value of x with with pre-plusplus = " . ++$x;
echo "The value of x after the pre-plusplus is " . $x;
?>
Display:
The
value of x with post-plusplus = 4 The
value of x after the post-plusplus is = 5 The value of x with
with pre-plusplus = 5 The value of x after the pre-plusplus is
= 5
All photograph,logos, articles, comments and trademarks -- etc in this site are property of their respective owners.All the rest (c) 2006 by PhpMyanmar.com.