Presentation is loading. Please wait.

Presentation is loading. Please wait.

Operators Operators are symbols such as + (addition), - (subtraction), and * (multiplication). Operators do something with values. $foo = 25; $foo – 15;

Similar presentations


Presentation on theme: "Operators Operators are symbols such as + (addition), - (subtraction), and * (multiplication). Operators do something with values. $foo = 25; $foo – 15;"— Presentation transcript:

1 Operators Operators are symbols such as + (addition), - (subtraction), and * (multiplication). Operators do something with values. $foo = 25; $foo – 15; // $foo and 15 are the operands, - is the operator

2 Arithmetic Operators + Addition $a + $b - Subtraction $a - $b
* Multiplication $a * $b / Division $a / $b % Modulus (modulus divides the first value by the second, and returns the remainder e.g. $foo = 9; echo ($foo % 4); // 1 )

3 Assignment Operators Assignment operators set the value of variables = Assignment $a = $b copies $b's value into $a =& Reference $a =& $b set $a to reference $b

4 Concatenation Operator
Concatenation means to put things together. The concatenation operator puts strings together. . Concatenation appends 2nd value to 1st $first = "Barack"; $second = "Obama" Echo ($first . " " . $second); // Barack Obama

5 Comparison Operators == Equals true if $a = $b === Identical true if $a = $b and of same type $x = 50; // integer $y = "50"; // string if ($x == $y) { echo "$x is the same as $y"; } // 50 is the same as 50

6 $x = 50; // integer $y = "50"; // string if ($x === $y) { echo "$x is the same as $y"; } else { echo "$x is not the same as $y"; } // 50 is not the same as 50

7 Comparison Operators != Not Equal true if $a is not equal to $b !== Not Identical true if $a is not identical to $b < Less Than true if $a is less than $b > Greater Than true if $a is greater than $b <= Less Than or Equal to >= Greater Than or Equal to

8 Increment/Decrement Operators
++$a pre-increment increments $a by 1, then returns $a $a++ post-increment returns $a, then increments $a by 1 --$a pre-decrement decrements $a by 1, $a-- post-decrement returns $a, then decrements by 1

9 $a = 10; echo $a++ . "<br />"; echo $a; // 10 11 echo ++$a; // 11

10 Logical Operators AND true if both $a AND $b are true $a = 10; $b = 5; if ($a > 5 AND $b >= 5) { echo "This is pretty cool"; } // This is pretty cool && is the same as AND

11 Logical Operators OR true if either $a AND $b are true $a = 10; $b = 5; if ($a > 5 OR $b > 5) { echo "This is pretty cool"; } // This is pretty cool || is the same as OR


Download ppt "Operators Operators are symbols such as + (addition), - (subtraction), and * (multiplication). Operators do something with values. $foo = 25; $foo – 15;"

Similar presentations


Ads by Google