11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

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

www.it-ebooks.infoCHAPTER 3 • <strong>PHP</strong> BASICSThis is the same as writing$total_cost = $cost + ($cost * 0.06);because the multiplication operator has higher precedence than the addition operator.Operator AssociativityThe associativity characteristic of an operator specifies how operations of the same precedence (i.e.,having the same precedence value, as displayed in Table 3-3) are evaluated as they are executed.Associativity can be performed in two directions, left-to-right or right-to-left. Left-to-right associativitymeans that the various operations making up the expression are evaluated from left to right. Considerthe following example:$value = 3 * 4 * 5 * 7 * 2;The preceding example is the same as the following:$value = ((((3 * 4) * 5) * 7) * 2);This expression results in the value 840 because the multiplication (*) operator is left-to-rightassociative.In contrast, right-to-left associativity evaluates operators of the same precedence from right to left:$c = 5;print $value = $a = $b = $c;The preceding example is the same as the following:$c = 5;$value = ($a = ($b = $c));When this expression is evaluated, variables $value, $a, $b, and $c will all contain the value 5because the assignment operator (=) has right-to-left associativity.Arithmetic OperatorsThe arithmetic operators, listed in Table 3-5, perform various mathematical operations and will probablybe used frequently in many of your <strong>PHP</strong> programs. Fortunately, they are easy to use.Incidentally, <strong>PHP</strong> provides a vast assortment of predefined mathematical functions capable ofperforming base conversions and calculating logarithms, square roots, geometric values, and more.Check the manual for an updated list of these functions.69

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

Saved successfully!

Ooh no, something went wrong!