1
0
mirror of https://github.com/restoreddev/phpapprentice.git synced 2025-07-13 19:46:18 +02:00
Files
phpapprentice/code/arithmetic.php
2018-12-26 19:01:06 -06:00

27 lines
709 B
PHP

<?php
// Now that we know how to create variables, let's look at doing some math.
$a = 1;
$b = 2;
// To add two values, use the plus symbol.
echo $a + $b;
// To subtract, use the minus symbol.
echo $b - $a;
// To multiply two values, use an asterisk.
echo $a * $b;
// To divide values, use a forward slash.
echo $b / $a;
// PHP uses the percent symbol for calculating the modulus of two numbers.
// The modulus is calculated by dividing two numbers and returning the remainder of the result.
// In this example, the value of $mod will be 0.
$mod = 10 % 5;
// You can also use double asterisks to calculate a number to the power of another number.
// The following statement will print 25.
echo 5 ** 2;