Sunday 22 June 2014

PHP Operators

PHP Arithmetic Operators:-

Operator
Name
Example
Result
+
Addition
$x + $y
Sum of $x and $y
-
Subtraction
$x - $y
Difference of $x and $y
*
Multiplication
$x * $y
Product of $x and $y
/
Division
$x / $y
Quotient of $x and $y
%
Modulus
$x % $y
Remainder of $x divided by $y

PHP String Operators:-

Operator
Name
Example
Result
.
Concatenation
$txt1 = "Hello"
$txt2 = $txt1 . " world!"
Now $txt2 contains "Hello world!"

PHP Increment / Decrement Operators:-

Operator
Name
Description
++$x
Pre-increment
Increments $x by one, then returns $x
$x++
Post-increment
Returns $x, then increments $x by one
--$x
Pre-decrement
Decrements $x by one, then returns $x
$x--
Post-decrement
Returns $x, then decrements $x by one

PHP Logical Operators:-

Operator
Name
Example
Result
&&
And
$x && $y
True if both $x and $y are true
||
Or
$x || $y
True if either $x or $y is true
!
Not
!$x
True if $x is not true