7Nov/090
PHP Operators (Basic PHP Operators)
Now that we have the variables lets do some maths using operators, operators are the symbols that connect all the variables together.
Simple maths with PHP:
<?php // Define variables $number1 = 123; $number2 = 2; // Add $total1 = $number1 + $number2; // Subtract $total2 = $number1 - $number2; // Multiply $total3 = $number1 * $number2; // Divide $total4 = $number1 / $number2; // Modulus $total5 = $number1 % $number2; ?>
Now lets use auto-increment and auto-decrement operators
Auto-increment
<?php // Define variable $total = 123; // increment it $total++; // $total is now 124 // This is the same as $total = $total + 1; ?>
Auto-decrement
<?php // Define variable $total = 123; // decrement it $total--; // $total is now 122 // This is the same as $total = $total - 1; ?>
No related posts.

