Sunday, December 11, 2011

PHP Numbers

Since we know what numbers are, lets look the following examples how to deal numbers using PHP.

Math Operations

It will echo back 12+4+$value1 and multiplied by $value2 then divided by 2 minus 5
$value1 = 4;
$value2 = 5;

echo ((12 + 4 + $value1) * $value2) / 2 - 5; // result is 45
Using +=, -=, *= and /= will update the value of $price
$price = 8;

echo $price += 8; echo ', '; // new value of $price = 16
echo $price -= 8; echo ', '; // new value of $price = 8
echo $price *= 8; echo ', '; // new value of $price = 64
echo $price /= 8; echo ', '; // new value of $price = 8
Incrementing (go up by 1)
$student = 4;

$student++; echo $student; // result is 5
Decrementing (go down by 1)
$student = 4;

$student--; echo $student; // result is 3

No comments:

Post a Comment