Number Functions PHP Essential Training

Number Functions PHP Essential Training

PHP

Number Functions PHP Essential Training

Welcome to another effective lesson in our essential training. In this lesson we're gonna learn in depth operations of the Number Functions PHP Essential Training. So far we teach what is the basic operations of the numbers functions. The numbers are played a very important role in mathematical and arithmetic operations. Checkout the previous lesson String Functions PHP Essential Training
Difficulty: Beginner
Time Duration: 30 Minutes
Requirements: XAMPP Installed PC, Text Editor(Sublime Text), Browser(Chrome)
Lets see what we can do with the various number functions and how handy they are compared with other programming and scripting language. In Php you really won't take care of what kind of number you are going to use. The PHP will understand itself when we store some data inside. Here we gonna show you the basic mathematical operations like Addition, Subtraction and etc.
<!DOCTYPE html>
<html>
<head>
<title>Numbers</title>
</head>
<body>
<?php
$var1 = 3;
$var2 = 4;
?>
//Guess what will be the Answer for the following expression
Basic Math: <?php echo((1 + 2 + $var1) * $var2) / 25; ?>
//If you're familiar with any other language like C++. You should know about the Operator precedence.
</body>
</html>
The answer will be 7 as follows
Number Functions PHP Essential Training

Extra Functions - Number Functions PHP Essential Training

The PHP has some other mathematical operators for perform complex equations. Here we show some important operations. As we saw our last lesson the concatenation is used here for join the variable and a value.
// Add the value 4 with variable $var2
Addition +=: <?php $var2 += 4; echo $var2; ?>
Number Functions PHP Essential Training

// Subtract the value 4 from variable $var2
Subtraction -=: <?php $var2 -= 4; echo $var2; ?>
Number Functions PHP Essential Training

// Multiply the value 4 with variable $var2
Multiplication *=: <?php $var2 *= 4; echo $var2; ?>
Number Functions PHP Essential Training

// Divide the value 4 from the variable $var2
Division /=: <?php $var2 /= 4; echo $var2; ?>
Number Functions PHP Essential Training

Like the above number functions we have some other functions like increment and decrement the values. This will helps us to automatically increase or decrease the value on a certain condition.
// This will increase the value by one in the variable &var2.
Increment: <?php $var2++; echo $var2; ?>
Number Functions PHP Essential Training

// This will decrease the value by one in the variable &var2.
Decrement: <?php $var2--; echo $var2; ?>
Number Functions PHP Essential Training
We hope this lesson will gives you an idea about the number functions in detailed view
Download the source Code of Number Functions PHP Essential Training from here.

Leave a Reply