mirror of
https://github.com/restoreddev/phpapprentice.git
synced 2025-08-11 01:04:11 +02:00
Created initial site setup with hugo
This commit is contained in:
40
content/03-arithmetic.md
Normal file
40
content/03-arithmetic.md
Normal file
@@ -0,0 +1,40 @@
|
||||
Now that we know how to create variables, let's look at doing some math.
|
||||
```php
|
||||
<?php
|
||||
|
||||
$a = 1;
|
||||
$b = 2;
|
||||
```
|
||||
|
||||
To add two values, use the plus symbol.
|
||||
```php
|
||||
echo $a + $b;
|
||||
```
|
||||
|
||||
To subtract, use the minus symbol.
|
||||
```php
|
||||
echo $b - $a;
|
||||
```
|
||||
|
||||
To multiply two values, use an asterisk.
|
||||
```php
|
||||
echo $a * $b;
|
||||
```
|
||||
|
||||
To divide values, use a forward slash.
|
||||
```php
|
||||
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.
|
||||
```php
|
||||
$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.
|
||||
```php
|
||||
echo 5 ** 2;
|
||||
```
|
Reference in New Issue
Block a user