Prev | Current Page 164 | Next

W. Jason Gilmore

"Beginning PHP and MySQL: From Novice to Professional"


90 CHAPTER 3 ?–  PHP B ASICS
Arithmetic Operators
The arithmetic operators, listed in Table 3-5, perform various mathematical operations
and will probably be used frequently in many of your PHP programs.
Fortunately, they are easy to use.
Incidentally, PHP provides a vast assortment of predefined mathematical functions
capable of performing base conversions and calculating logarithms, square
roots, geometric values, and more. Check the manual for an updated list of these
functions.
Assignment Operators
The assignment operators assign a data value to a variable. The simplest form of
assignment operator just assigns some value, while others (known as shortcut assignment
operators) perform some other operation before making the assignment. Table
3-6 lists examples using this type of operator.
Table 3-5. Arithmetic Operators
Example Label Outcome
$a + $b Addition Sum of $a and $b
$a - $b Subtraction Difference of $a and $b
$a * $b Multiplication Product of $a and $b
$a / $b Division Quotient of $a and $b
$a % $b Modulus Remainder of $a divided by $b
Table 3-6. Assignment Operators
Example Label Outcome
$a = 5 Assignment $a equals 5
$a += 5 Addition-assignment $a equals $a plus 5
$a *= 5 Multiplication-assignment $a equals $a multiplied by 5
$a /= 5 Division-assignment $a equals $a divided by 5
$a .= 5 Concatenation-assignment $a equals $a concatenated with 5
CHAPTER 3 ?–  PHP BASICS 91
String Operators
PHP??™s string operators (see Table 3-7) provide a convenient way in which to concatenate
strings together.


Pages:
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176