4.3.7. Define the operators
From Computer Science
Revision as of 19:31, 7 November 2016 by Mr Russell (Talk | contribs)
All programming languages have a number of essential operators. Operators are the commands that compare, affect (change) or calculate something. The following essential operators are required byt he IB:
Comparison Operators
Comparison operators evaluate whether two variables are equal, and if not, how they are different:
| Operator | Name | PHP Syntax | Explaination | Usage example |
|---|---|---|---|---|
| = | Equals | == or === | Compares two numbers or strings to see if they are the same.
PHP: == converts the variables to the same data type and evaluates the values, while === evaluates both values and data type |
if ($x == $y) { do something } |
| ≠ | Not Equal to | != | ||
| < | Less than | < | ||
| > | Greater than | > | ||
| <= | Less than or equal to | <= | ||
| >= | Greater than or equal to | >= |
Calculation Operators
Clculation operators perform basic arithmatic on variables and return a result:
| Operator | Name | PHP Syntax | Explaination | Usage example |
|---|---|---|---|---|
| + | Addition | + or ++ | Compares two numbers or strings to see if they are the same.
PHP: == converts the variables to the same data type and evaluates the values, while === evaluates both values and data type |
if ($x == $y) { do something } |
| - | Subtraction | - or -- | ||
| * | Multiplication | |||
| / | Floating Point division | / | ||
| Div | Integer Division | div | ||
| Mod | Modulus | mod |