About us Privacy Disclaimer Contact us
FAQ Help Advertising Feedback
Home Sitemap Search Donate us

  Home > Computer & I'net > Numbers - Math...

   Browse by title articles:
   What is hot:

Escape Characters

Operators

Print/Echo

Variables

Numbers - Formatting

Numbers - Math

PHP File Attachments
Include
Six Golden Rules of a Pay Per Click Marketing Campaign
Module mod_rewrite Tutorial (Part 2)
Prev articles12345 6 789101112Next articles



Numbers - Math


Computer & I'net articlesNumbers - Math

by David Stanley    



Numbers can be added, subtracted, multiplied, divided, put into variables, formatted, and so on.

<?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.





Spouse Work




  Disclaimer | Privacy | Terms of useCopyright © 2004 Nice2know.com