Programming in PHP - Math Operators
Posted 01/30/2015 at 16:02 by manulaiko3.0
Copy and paste from my website: 
Here we are, maths, one of the things that I most hate, but why this tutorial is about math?
In programming 70% is math (the rest are syntax errors), so, if you want to code, you’ll fell in love with maths, or you will improve your logic as much as possible to don’t use maths
What are operators?
Remember when I was 7, in math class the teacher said “Maths are really important” and I think that’s one of the things that I’ve most used in my life. Well, that’s the only thing I learnt in school… maybe I learnt to read/write in school too… and to speak properly… and maybe something more, but what I want to say is that maths are really important, you get the idea right?
So, back on topic, operators are those easy maths things that you know since you were 7:
Plus
The plus operator, it bassically takes to integers and returns the result… easy right?
<?php $int1 = 123; $int2 = 321; $plus = $int1 + $int2; //That's the same as 123 + 321 = 444 (3 fours, 3! Illuminati confirmed!!!) ?> So, nothing else, the same with the rest of the operators.
Minus
Moar code!!
<?php $int1 = 333; $int2 = 111; $minus = $int1 - $int2; //333 - 111 = 222 ?> Multiplicator
<?php $int1 = 123; $int2 = 413; $multiplication = $int1 * $int2; //123 * 413 (I'm not going to do the maths -.-) ?< Division
<?php $int1 = 214; $int2 = 412; $division = $int1 / $int2; //214 / 412 ?> Module
Well, you might not know this operator, so I’ll explain what it does:
Consider having a division:
To check it just do:
Basically, the module operator returns the rest of a division.
Because…
<?php $int1 = 32; $int2 = 3; $module = $int1 % $int2; //2 /* * Same as this: * * 32 / 3 = 10 * 10 * 3 = 30 * 32 - 30 = 2 * 2!!! */ So, it’s done, nothing else about operators untill next chapter: Logical Operators.
See you!!

Here we are, maths, one of the things that I most hate, but why this tutorial is about math?
In programming 70% is math (the rest are syntax errors), so, if you want to code, you’ll fell in love with maths, or you will improve your logic as much as possible to don’t use maths
What are operators?
Remember when I was 7, in math class the teacher said “Maths are really important” and I think that’s one of the things that I’ve most used in my life. Well, that’s the only thing I learnt in school… maybe I learnt to read/write in school too… and to speak properly… and maybe something more, but what I want to say is that maths are really important, you get the idea right?
So, back on topic, operators are those easy maths things that you know since you were 7:
+Yeah, there’s nothing else (or maybe yes…), let’s see how operators works.
–
*
/
Plus
The plus operator, it bassically takes to integers and returns the result… easy right?
<?php $int1 = 123; $int2 = 321; $plus = $int1 + $int2; //That's the same as 123 + 321 = 444 (3 fours, 3! Illuminati confirmed!!!) ?> So, nothing else, the same with the rest of the operators.
Minus
Moar code!!
<?php $int1 = 333; $int2 = 111; $minus = $int1 - $int2; //333 - 111 = 222 ?> Multiplicator
<?php $int1 = 123; $int2 = 413; $multiplication = $int1 * $int2; //123 * 413 (I'm not going to do the maths -.-) ?< Division
<?php $int1 = 214; $int2 = 412; $division = $int1 / $int2; //214 / 412 ?> Module
Well, you might not know this operator, so I’ll explain what it does:
Consider having a division:
11 / 2This will return 5 (if we don’t care about decimals), but that’s not the correct result.
To check it just do:
5 * 2 = 10It returns 10, but 10 != 11!!!
Basically, the module operator returns the rest of a division.
11 % 2 = 1Why?
Because…
11 / 2 = 5Let’s see some code…
5 * 2 = 10
10 – 11 = 1!!! ILLUMINATI CONFIRMED!!!
<?php $int1 = 32; $int2 = 3; $module = $int1 % $int2; //2 /* * Same as this: * * 32 / 3 = 10 * 10 * 3 = 30 * 32 - 30 = 2 * 2!!! */ So, it’s done, nothing else about operators untill next chapter: Logical Operators.
See you!!
Total Comments 0






