25.09.2014 Views

ZEND PHP 5 Certification STUDY GUIDE

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

16 ” <strong>PHP</strong> Basics<br />

Arithmetic Operators<br />

Arithmetic operators allow you to perform basic mathematical operations:<br />

Addition $a = 1 + 3.5;<br />

Subtraction $a = 4 - 2;<br />

Multiplication $a = 8 * 3;<br />

Division $a = 15 / 5;<br />

Modulus $a = 23 % 7;<br />

i<br />

Do remember that certain arithmetic operators (for example, the addition operator)<br />

assume a different meaning when applied to arrays. You can find more information<br />

on this subject in the Arrays chapter.<br />

Incrementing/decrementing operators are a special category of operators that<br />

make it possible to increment or decrement the value of an integer by one. They<br />

are unary operators, because they only accept one operand (that is, the variable that<br />

needs to be incremented or decremented), and are somewhat of an oddity, in that<br />

their behaviour changes depending on whether they are appended or prepended to<br />

their operand.<br />

The position of the operator determines whether the adjustment it performs takes<br />

place prior to, or after returning the value:<br />

• If the operator is placed after its operand, the interpreter will first return the<br />

value of the latter (unchanged), and then either increment or decrement it by<br />

one.<br />

• If the operator is placed before the operand, the interpreter will first increment<br />

or decrement the value of the latter, and then return the newly-calculated<br />

value.<br />

Here are a few examples:<br />

Licensed to 482634 - Amber Barrow (itsadmin@deakin.edu.au)<br />

$a = 1;<br />

// Assign the integer 1 to $a

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!