3.12.1 Shorthand unary operatorsThis is NOT the latest copy of this book; click here for the latest version.
The = operator is special in that you can combine it with other operators. For example, to turn > (greater than) into greater than or equals, add the equals sign to the end - >=. You can add an equals sign to each of the first six operators in the list, forming +=, -=, *=, /=, and .=, and these become unary operators, like this:
<?php
$somevar = 5;
$somevar += 5; // $somevar is now 10
$somevar *= 2; // $somevar is now 20
$somevar .= " elephants"; // $somevar is now "20 elephants" ?>
The unary versions of these operators are really just shorthand, but they are a little easier to read also.
|
Want to see this stuff in print? PHP in a Nutshell takes the core topics covered here, adds in thousands of edits from the editorial team and myself, and combines them to make an unbeatable reference for PHP programmers at all levels.
My latest book has hundreds more tips on how to use PHP, Apache, and MySQL, plus Perl, Python, shell scripts, performance tuning, and more!
|