Linux Today: Linux News On Internet Time.

Math & Number Handling in PHP - The ABCs of PHP Part 6

Apr 21, 2009, 18:02 (0 Talkback[s])
(Other stories by Peter Shaw)

"Basic Operators

"The standard arithmetic operators are available in PHP and these are the same as in any other language:

+ Addition of numbers (20+10)
- Subtraction of numbers (20-10)
* Multiplication of numbers (20*10)
/ Division of numbers (20/10)

"When setting up or assigning variables, you can set the initial value to the result of a mathematical equation, as in the following example:

$result = 2+2; // $result will be equal to 4

For subtraction and addition there's also a very handy shortcut or two which are great for loop handling, these shortcuts are used by appending either a double + or a double - after the variable name:

$a = 1; // $a equals to 1
$a++; // $a equals 2
$a--; // $a once again equals 1

Complete Story

Related Stories: