PHP has a wide range of operators. Many of them will be familiar to you, a few may be new.
Assignment Operator
| = | Assignment Operator |
$x = 2 ; $cost = 29.95 ; $name = 'Harvey' ; $y = $x ; |
Arithmetic Operators
| + | Addition Operator |
$x = 2 + 2 ; $y = $x + $z ; $fruit = $apples + $oranges ; | |
| - | Subtraction Operator |
$y = 29 - 17 ; $x = $y - $x ; $z = $z - 1 ; | |
| * | Multiplication Operator |
$gross = 12 * 12 ; $twogross = $gross * 2 ; | |
| / | Division Operator |
$z = 12 / 4 ; $x = 14 / 3 ; | |
| % | Modulus (or Remainder) Operator |
$x = 14 % 3 ; $y = $x % 2 ; | |
| ++ | Increment and |
| -- | Decrement Operator |
$x++ ; // post-increment ++$x ; // pre-increment $y-- ; // post-decrement --$y ; // pre-decrement $y = 5 ; $x = $y++ ; // $x equals 5, $y equals 6 $y = 5 ; $x = ++$y ; // $x and $y both equal 6 | |
| In PHP, increment and decrement operators can be applied to strings as well as numbers. | |
$x = 'y' ; $x++ ; // now $x is 'z' $x++ ; // now $x is 'aa' $x = 'spaz' ; $x++ ; // now $x is 'spba' $x = 'K9' ; $x++ ; // now $x is 'L0' ; |
There is a list of all the PHP operators here.
Copyright © 2003
Henry H. Hartley
All Rights Reserved