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
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.
$var1 = 3;
$var2 = 4;
//Guess what will be the Answer for the following expression
Basic Math: <?php echo((1 + 2 + $var1) * $var2) / 2 − 5; ?>
//If you're familiar with any other language like C++. You should know about the Operator precedence.
The answer will be 7 as follows
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; ?>
// Subtract the value 4 from variable $var2
Subtraction -=: <?php $var2 -= 4; echo $var2; ?>
// Multiply the value 4 with variable $var2
Multiplication *=: <?php $var2 *= 4; echo $var2; ?>
// Divide the value 4 from the variable $var2
Division /=: <?php $var2 /= 4; echo $var2; ?>
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; ?>
// This will decrease the value by one in the variable &var2.
Decrement: <?php $var2--; echo $var2; ?>
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.