This tutorial isn't as important as the last one, feel free to skip it if you'd like.
Part 1 - Using PHP as a calculator:
Using the stuff we learned from the other thread (variables and our echo function), we can use PHP to do basic math calculations for us.
So, let's say you want to know what 2+2 is.
Well, here is how you would write it:
It would echo the result out on the screen. In this case, it would echo out the number 4.
You can also use more than 1 variable and do the math in your echo statement.
For example:
It would add the 2 variables and give us our result, which would be 9.
Now, let's say you want to multiply, divide, or maybe subtract.
Here's what you would do (I'll add comments in the code so that I don't have to add multiple codes):
There are many other things you can do, look them up if you'd like to know.
I think that's about it for now.
This wasn't a 100% needed tutorial, but it's something that's nice to know.
Part 1 - Using PHP as a calculator:
Using the stuff we learned from the other thread (variables and our echo function), we can use PHP to do basic math calculations for us.
So, let's say you want to know what 2+2 is.
Well, here is how you would write it:
PHP:
<?php
$math=2+2;
echo $math;
?>
It would echo the result out on the screen. In this case, it would echo out the number 4.
You can also use more than 1 variable and do the math in your echo statement.
For example:
PHP:
<?php
$math1=5;
$math2=4;
echo $math1+$math2;
?>
It would add the 2 variables and give us our result, which would be 9.
Now, let's say you want to multiply, divide, or maybe subtract.
Here's what you would do (I'll add comments in the code so that I don't have to add multiple codes):
PHP:
<?php
$math1=10;
$math2=20;
//If you want to multiply, use *
//If you want to divide, use /
//If you want to subtract, use -
//If you want to divide and get the remainder, use %
echo $math1*$math2;
?>
There are many other things you can do, look them up if you'd like to know.
I think that's about it for now.
This wasn't a 100% needed tutorial, but it's something that's nice to know.