|
Operator |
Description [Example] |
|
+
|
Addition - finds the sum of 2 values
print 3 + 3;//The output will be: 6
|
|
*
|
Multiplication - Multiplies 2 values
print 2 * 3;//The output will be: 6
|
|
-
|
Subtraction - finds the difference
between 2 values
print 6 - 3;//The output will be: 3
|
|
/
|
Division - Divides one value by
another value
print 9 / 3;//The output will be: 3
|
|
%
|
Modulus - Divides one value by another value and returns only the remainder ion the result.
print 7 % 5;//The output will be: 2
|
|
.
|
Concatenation - Combine values into a
string.
$temp = "hot";
$myString = "It is " . $temp . " today.";
print $myString;//The output will be: It is hot today.
|
|
++value
|
Pre-increment - Adds 1 to a value before the expression that uses the value is processed.
$a = 5;
print ++$a;//The output will be: 6
|
|
--value
|
Pre-decrement - Subtracts 1 to a value before the expression that uses the value is processed.
$a = 5;
print --$a;//The output will be: 4
|
|
value++
|
Post-increment - Adds 1 to a value after the expression that uses the value is processed.
$a = 5;
print $a++;print "<br>";
print $a;//The output will be: //5//6
|
|
value--
|
Post-decrement - Subtracts 1 to a value after the expression that uses the value is processed.
$a = 5;
print $a--;print "<br>";
print $a;//The output will be: //5//4
|
|
=
|
Assignment - Sets 1 value to another value.
$a = 3;
print $a;//The output will be: 3
|
|
+=
|
Assignment - Adds 1 value to another value.
$a = 3;
$a += 3;
print $a;//The output will be: 6
|
|
-=
|
Assignment - Subtracts 1 value from another value.
$a = 3;
$a -= 1;
print $a;//The output will be: 2
|
|
*=
|
Assignment - Multiplies 1 value by another value.
$a = 3;
$a *= 2;
print $a;//The output will be: 6
|
|
/=
|
Assignment - Divides 1 value by another value.
$a = 6;
$a /= 2;
print $a;//The output will be: 3
|
|
.=
|
Assignment - Combines 2 values.
$a = "This is ";
$a .= "a test.";
print $a;//The output will be: This is a test
|
|
==
|
Equal to - Checks if one value is equal to another value.
$x = 7;
$y = "7";
if ($x == $y) print $x . " is equal to " . $y;
//The output will be: 7 is equal to 7
|
|
===
|
Identical to - Checks if one value is equal to and of the same type as another value.
$x = 7;
$y = 7;
if ($x === $y) print $x . " is identical to " . $y;
//The output will be: 7 is identical to 7
|
|
!=
|
Not equal to - Checks if one value is not equal to another value.
$x = 8;
$y = 4;
if ($x != $y) print $x . " is not equal to " . $y;
//The output will be: 8 is not equal to 4
|
|
!==
|
Not identical to - Checks if 2 values are not equal to or of the same type.
$x = 8;
$y = 9;
if ($x != $y) print $x . " is not identical to " . $y;
//The output will be: 8 is not identical to 9
|
|
<
|
Less Than - Checks if 1 value is less than another value.
$x = 5;
$y = 9;
if ($x < $y) print $x . " is less than " . $y;
//The output will be: 5 is less than 9
|
|
>
|
Greater Than - Checks if 1 value is greater than another value.
$x = 9;
$y = 5; if ($x > $y) print $x . " is less than " . $y;
//The output will be: 9 is less than 5
|
|
<=
|
Less Than or Equal to - Checks if 1 value is less than or equal to another value.
$x = 5;
$y = 5; if ($x <= $y) print $x;
//The output will be: 5
|
|
>=
|
Greater Than or Equal to - Checks if 1 value is greater than or equal to another value.
$x = 7;
$y = 5;
if ($x >= $y) print $x;
//The output will be: 7
|
|
And
|
Checks if 2 or more statements are true.
$x = 7;
$y = 5;
if (($x == 7) and ($y == 5)) print "true";
//The output will be: true
|
|
Or
|
Checks if at least 1 of 2 statements is true.
$x = 7;
$y = 5;
if (($x == 7) or ($y == 8)) print "true";
//The output will be: true
|
|
Xor
|
Checks if only 1 of 2 statements is true.
$x = 7;
$y = 5;
if (($x == 7) xor ($y == 8)) print "true";
//The output will be: true
|
|
!
|
Checks if the statements is not true.
$y = 5;
if (! ($x == 10)) print "true";
//The output will be: true
|
|
&&
|
Checks if 2 or more statements are both true.
$x = 7;
$y = 5;
if (($x == 7) && ($y == 5)) print "true";
//The output will be: true
|
|
||
|
Checks if at least 1 of 2 statements is true.
$x = 7;
$y = 5;
if (($x == 7) || ($y == 5)) print "true";
//The output will be: true
|