PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I was looking around good old spoono and I've just came across the alternative row coloring tutorial. So I took a look at it. I understood everything except the $i % 2.
<?php
for($i=0; $i!=13; $i++)
echo 'the remainder of ', $i, '/4 is ', $i%4, " \n<br />";
?>
outputs:
the remainder of 0/4 is 0
the remainder of 1/4 is 1
the remainder of 2/4 is 2
the remainder of 3/4 is 3
the remainder of 4/4 is 0
the remainder of 5/4 is 1
the remainder of 6/4 is 2
the remainder of 7/4 is 3
the remainder of 8/4 is 0
the remainder of 9/4 is 1
the remainder of 10/4 is 2
the remainder of 11/4 is 3
the remainder of 12/4 is 0
The mysterey of 0,1,2,3. I can code PHP but I'm not the best of maths in class - that's another story .
-Nay
ps: yes, this means I still don't really get it. I'm still reading over the operators in the documentation
<pre><?php
$i = 5; // change this if you like
$result = $i/4;
echo $i, ' divided by 4 is: ', $result, "\n";
echo $result, ' four times is: ', $result*4, "\n";
echo $i, ' - ', $result*4, ' is: ', $i-($result*4), "\n";
echo "---\n";
echo "now we only have integers\n";
$result = (int)($i/4);
echo $i, ' divided by 4 is: ', $result, "\n";
echo $result, ' four times is: ', $result*4, "\n";
echo $i, ' - ', $result*4, ' is: ', $i-($result*4), "\n";
echo "---\n";
echo $i, ' modulus 4 is: ', $i%4, "\n";
echo "---\n";
echo '4 is ', $result, ' times in ', $i, '. Remainder: ', $i%4, "\n";
?></pre>
I asked my sister if she knows modulus in maths soon after I was tearing my hair off. Well, she graduated top in her maths classes so yeah, I thought I give it a try.