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> BASICSTable 3-7. String OperatorsExample Label Outcome$a = "abc"."def"; Concatenation $a is assigned the string "abcdef"$a .= "ghijkl"; Concatenation-assignment $a equals its current value concatenated with "ghijkl"Here is an example involving string operators:// $a contains the string value "Spaghetti & Meatballs";$a = "Spaghetti" . "& Meatballs";$a .= " are delicious."// $a contains the value "Spaghetti & Meatballs are delicious."The two concatenation operators are hardly the extent of <strong>PHP</strong>’s string-handling capabilities. SeeChapter 9 for a complete accounting of this important feature.Increment and Decrement OperatorsThe increment (++) and decrement (--) operators listed in Table 3-8 present a minor convenience interms of code clarity, providing shortened means by which you can add 1 to or subtract 1 from thecurrent value of a variable.Table 3-8. Increment and Decrement OperatorsExample Label Outcome++$a, $a++ Increment Increment $a by 1--$a, $a-- Decrement Decrement $a by 1These operators can be placed on either side of a variable, and the side on which they are placedprovides a slightly different effect. Consider the outcomes of the following examples:$inv = 15; // Assign integer value 15 to $inv.$oldInv = $inv--; // Assign $oldInv the value of $inv, then decrement $inv.$origInv = ++$inv; // Increment $inv, then assign the new $inv value to $origInv.As you can see, the order in which the increment and decrement operators are used has animportant effect on the value of a variable. Prefixing the operand with one of these operators is known asa preincrement and predecrement operation, while postfixing the operand is known as a postincrementand postdecrement operation.71

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

Saved successfully!

Ooh no, something went wrong!