Example | Name | Result |
---|---|---|

-$a | Negation | Opposite of .$a |

$a + $b | Addition | Sum of and $a.$b |

$a – $b | Subtraction | Difference of and $a.$b |

$a * $b | Multiplication | Product of and $a.$b |

$a / $b | Division | Quotient of and $a.$b |

$a % $b | Modulus | Remainder of divided by $a.$b |

# Category Archives: Operators in php

## PHP Arithmatic Operator

## PHP-Logical Operator

Example | Name | Result |
---|---|---|

$a and $b | And | if both $a and $b are TRUE.TRUE |

$a or $b | Or | if either $a or $b is TRUE.TRUE |

$a xor $b | Xor | if either $a or $b is TRUE, but not both.TRUE |

! $a | Not | if $a is not TRUE.TRUE |

$a && $b | And | if both $a and $b are TRUE.TRUE |

$a || $b | Or | if either $a or $b is TRUE.`TRUE |

**Check out this example**

<?php

$a=TRUE; //1

$b=FALSE;//null 0

Echo “A has:”.(bool)$a;

echo”B has:”.(bool)$b;

echo “A AND B has: “;

echo $a && $b;

echo “A OR B has: “;

echo $a || $b;

?>

## Increment/Decrement operator in php

This may seem a bit confusing, but there is even a shorter shorthand for the common task of 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;

**Study this example:**

<?php

$a = 5;

echo “<h2>A initially is “.$a.”.</h2>”;

echo “<h3>Postincrement</h3>”;

echo “Should be 5: ” . $a++ . “<br />\n”;

echo “Should be 6: ” . $a . “<br />\n”;

echo “<h3>Preincrement</h3>”;

$a = 5;

echo “A is reset to: “.$a. “<br />\n”;

echo “Should be 6: ” . ++$a . “<br />\n”;

echo “Should be 6: ” . $a . “<br />\n”;

echo “<h3>Postdecrement</h3>”;

$a = 5;

echo “A is reset to: “.$a. “<br />\n”;

echo “Should be 5: ” . $a– . “<br />\n”;

echo “Should be 4: ” . $a . “<br />\n”;

echo “<h3>Predecrement</h3>”;

$a = 5;

echo “A is reset to: “.$a. “<br />\n”;

echo “Should be 4: ” . –$a . “<br />\n”;

echo “Should be 4: ” . $a . “<br />\n”;

?>

## php-comparision operator

Comparisons 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. Here are the most important comparison operators of PHP.

** **

** *** *

Operator | Desc | 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 |

*Check out this example:*

<?php

$a=10;

$b=17;

/*

$a=17;

$b=10;

*/

echoÃƒâ€šÃ‚Â “<br>A is : “.$a;

echoÃƒâ€šÃ‚Â “<br>B is : “.$b;

echo “<br><br>”;

if($a==$b)

{

echo”<br>A equals B.”;//it wont be true

}

if($a != $b){

echoÃƒâ€šÃ‚Â “<br>A is not equals to B.”;//it will be true

}

if($a < $b){

echoÃƒâ€šÃ‚Â “<br>A is less than B;”;

}

if($a > $b){

echoÃƒâ€šÃ‚Â “<br>A is greater than B;”;

}

if($a <= $b){

echoÃƒâ€šÃ‚Â “<br>A is less than or equals to B;”;

}

if($a >= $b){

echo “<br>A is greater than or equals to B;”;

}

?>

## php – operators

An operator is something that you feed with one or more values (or expressions, in programming jargon) which yields another value (so that the construction itself becomes an expression).Operators are used to manipulate or perform operations on variables and values.

There are many operators used in PHP.

1. Comparison Operator

2. Increment/Decrement Operator

3. Logical Operator

4. Arithmatic Operator