| Home > Computer & I'net > Numbers - Math... |
|
|
|||||||||||||||
|
|
|||||||||||||||
|
||||||||||||||||
Numbers - Math | |
<?php $number = 10; $number = $number + 1; echo "$number"; ?> Outcome : 11 Math in PHP follows the same precedence rules as regular math. BEDMAS. From most important to least important is : Brackets Exponents Division Muliplication Addition Subtraction <?php $first_number = 10 - 4 / 2; $second_number = (10 - 4) / 2; echo "$first_number <br />"; echo "$second_number"; ?> Outcome : 8 3 A simple shortcut method may be used to add or subtract 1 from a number. <?php $number = 10; $number++; // that is the same as saying $number=$number+1; echo "$number"; ?> Outcome : 11 Can you guess what you would put to decrease a number by one? For those who are having a brain fuzzy : <?php $number = 10; $number--; // that is the same as saying $number=$number-1; echo "$number"; ?> Outcome : 9
----------------- Article by David Stanley. Visit his site http://www.htmlite.com. Reprinted with permission. | |
| Articles |
•Auto & Trucks•Business•Computer & I'net·General·Apache·CSS·Database·Hardware·HTML·Javascript&DHTML·Linux·MySQL·Operating System·Perl / CGIPHP·Programming·Publishing·Search Engines·Software Problems·SSI·Tips & Tricks·Utilities·Web Design•Family•Food & Drink•Gardening•Health•Other•Pets•Psychology•Spiritual•Travel•Women |
| Calculators |
|