PHP has both integer and float (decimal) number types. These two types can be classified under the generic title numbers.
Valid numbers can be anything like:   8,   258,   -37,   89.25,   -3.5785,   5.5e2
- Number-type values are never quoted. The numbers added within quotes are strings with numeric values.
PHP supports a maximum integer of around two billion on most platforms (UNIX and Windows). With numbers larger than that, PHP will automatically use a floating-point type.

### 1. Numbers and Operator

The mathematical operators are specific symbols that performs mathematical calculations.
Operators act on the variables and numbers presented in PHP instructions.

#### The standard mathematical (Arithmetic) operators

```<?php
\$x = 5;
\$y = \$x + 3;
echo \$y;                 // 8
?>
```
• Subtraction ( - )
```<?php
\$x = 5;
\$y = \$x - 3;
echo \$y;                 // 2
?>
```
• Multiplication ( * )
```<?php
\$x = 5;
\$y = \$x * 3;
echo \$y;                 // 15
?>
```
• Division ( / )
```<?php
\$x = 5;
\$y = \$x / 3;
echo \$y;                 // 1.6666666666667
?>
```
• Modulus (division remainder) ( % )
```<?php
\$x = 5;
\$y = \$x % 3;
echo \$y;                 // 2
?>
```
• Increment ( ++ )
```<?php
\$x = 5;
\$x++;             // Ecivalent with:  \$x = \$x + 1;
echo \$x;                 // 6
?>
```
• Decrement ( -- )
```<?php
\$x = 5;
\$x--;             // Ecivalent with:  \$x = \$x - 1;
echo \$x;                 // 4
?>
```

#### Assignment Operators

• ( = )
```<?php
\$x = 5;
\$y = \$x;
echo \$y;                 // 5
?>
```
• ( += )
```<?php
\$x = 5;
\$x += 3;             // Ecivalent with:  \$x = \$x + 3;
echo \$x;                 // 8
?>
```
• ( -= )
```<?php
\$x = 5;
\$x -= 3;             // Ecivalent with:  \$x = \$x - 3;
echo \$x;                 // 2
?>
```
• ( *= )
```<?php
\$x = 5;
\$x *= 3;             // Ecivalent with:  \$x = \$x * 3;
echo \$x;                 // 15
?>
```
• ( /= )
```<?php
\$x = 5;
\$x /= 2;             // Ecivalent with:  \$x = \$x / 2;
echo \$x;                 // 2.5
?>
```
• ( .= )
```<?php
\$x = 5;
\$x .= 3;             // Ecivalent with:  \$x = \$x . 3;
echo \$x;                 // 53
?>
```
• ( %= )
```<?php
\$x = 5;
\$x %= 2;             // Ecivalent with:  \$x = \$x % 2;
echo \$x;                 // 1
?>
```

The mathematical calculations in PHP, as in arithmetic, are taken into account the operators precedence (the order in which complex calculations are made). If you want to force the execution order, you must group clauses in parentheses. Check the fallowing example:
```<?php
\$x = 8 + 3 * 5 -2;
echo \$x;                  // 21 (first 3*5 [15], then adds 8 and substract 2 )

\$x = (8+3) * (5-2);
echo '<br />'. \$x;        // 33  (first 8+3  [11], then  5-2 [3], then makes the multiplication  11*3 [33] )
?>
```

### 2. PHP mathematical functions

Along with the arithmetic operators you can use PHP mathematical functions for more complex operations.
Here are some examples of functions:
• abs(x) - The absolute value of "x"
```<?php
\$x = abs(-3.5);            // \$x = 3.5;
\$y = abs(-4);              // \$y = 4;
?>
```
• ceil(x) - "x" rounded up to the next highest integer
```<?php
\$x = ceil(3.5);            // \$x = 4;
\$y = ceil(-8.5);           // \$y = -8;
?>
```
• floor(x) - "x" rounded to the next lowest integer
```<?php
\$x = floor(3.5);            // \$x = 3;
\$y = floor(-8.5);           // \$y = -9;
?>
```
• max(x, y, ...) - returns the highest of the parameter values
```<?php
\$x = max(5, 88, -12, 78.4);
echo \$x;                       // 88
?>
```
• min(x, y, ...) - returns the lowest of the parameter values
```<?php
\$x = min(5, 88, -12, 78.4);
echo \$x;                       // -12
?>
```
• number_format(x, d) - Turns a number into the more commonly written version, grouped into thousands using commas. Also, can set a specified number of decimal points, specified by "d" parameter:
```<?php
\$x = 35788;
\$x = number_format(\$x);
echo \$x;                   // 35,788

\$y = 35788.3;
\$y = number_format(\$y, 2);
echo '<br />'. \$y;                   // 35,788.30
?>
```
• pow(x, n) - "x" raised to the power of "n"
```<?php
\$x = pow(3, 4);
echo \$x;             // 81
?>
```
• sqrt(x) - The square root of "x" or the special value NAN for negative numbers
```<?php
\$x = sqrt(64);
echo \$x;             // 8
?>
```

#### Daily Test with Code Example

##### PHP-MySQL
Which attribute can be used to add CSS styles directly in the HTML tag?
type style class
`<div style="width: 80%; border: 3px solid #888888;">Content</div>`
Which CSS transform method distorts the HTML element in a given angle (including its content)?
translate() scale() skew()
```#some_id {
transform: skew(20deg, 25deg);
-ms-transform: skew(20deg, 25deg);   /* IE 9 */
-webkit-transform: skew(20deg, 25deg);   /* Safari and Chrome */
}```
Click on the function which converts a Date object to a string.
indexOf() toString() getDate()
```var rightnow = new Date();
Which function applies a callback function to the elements of the given array?
array_merge() array_search() array_map()
```\$arr = arra("abc", "<p>xyz</p>", "<em>PHP</em>");
// apply the strip_tags() function to delete HTML tags from each array item
\$arr = array_map("strip_tags", \$arr);
}```
Numbers and mathematical 0perators

#### Last accessed pages

1. SHA512 Encrypt hash in JavaScript (7775)
2. Mahjong Games (17768)
3. Create simple Website with PHP (16216)
4. Add data from form in text file in JSON format (8983)
5. Zodiac Signs JavaScript code (3678)

#### Popular pages this month

1. Qwop (3030)
2. Drag Racer V3 (1516)
3. Bubbles3 (727)
4. Flash Games - Free online Games (677)
5. Courses Web: PHP-MySQL JavaScript Ajax HTML CSS Flash-AS3 (665)