silverglade Posted June 12, 2011 Share Posted June 12, 2011 I have no clue what is going on. It is driving me insane so I am trying the forum. The below code is self explanatory, and I posted my sample output after the code. Any help greatly appreciated. thank you. here is the code <?php echo "<br /> Now for some math!!<br />"; $int1 = 2; $int2 = 3; echo "<br /> \$int2 + \$int1 = ".$int2 + $int1. " ."; //subtracting echo "<br /> \$int2 - \$int1 = ".$int2 - $int1. " ."; //multiply echo " <br /> \$int1 X \$int2 = ".$int1 * $int2." ."; //divide echo "<br /> \$int2 divided / by \$int1 = ".$int2 / $int1. " ."; //remainder or modulus operator echo "<br /> \$int2 remainder of \$int1 = ". $int2 % $int1. " ."; ?> Sample output is this: Now for some math!! 2 .-2 . $int1 X $int2 = 6 . $int2 divided / by $int1 = 1.5 . $int2 remainder of $int1 = 1 . Quote Link to comment https://forums.phpfreaks.com/topic/239107-super-easy-problem-involving-simple-math-functions/ Share on other sites More sharing options...
spiderwell Posted June 12, 2011 Share Posted June 12, 2011 telling us the values of $int1 and $int2 might help or that self explanatory too Quote Link to comment https://forums.phpfreaks.com/topic/239107-super-easy-problem-involving-simple-math-functions/#findComment-1228535 Share on other sites More sharing options...
silverglade Posted June 12, 2011 Author Share Posted June 12, 2011 sorry i just added that Quote Link to comment https://forums.phpfreaks.com/topic/239107-super-easy-problem-involving-simple-math-functions/#findComment-1228536 Share on other sites More sharing options...
spiderwell Posted June 12, 2011 Share Posted June 12, 2011 putting ($int2-$int1) did it for me same on the + Quote Link to comment https://forums.phpfreaks.com/topic/239107-super-easy-problem-involving-simple-math-functions/#findComment-1228538 Share on other sites More sharing options...
Pikachu2000 Posted June 12, 2011 Share Posted June 12, 2011 Enclose the math operations in parentheses to force the calculation to be performed before the value is echoed. <?php echo "<br /> Now for some math!!<br />"; $int1 = 2; $int2 = 3; echo "<br /> \$int2 + \$int1 = " . ($int2 + $int1); //subtracting echo "<br /> \$int2 - \$int1 = " . ($int2 - $int1); //multiply echo " <br /> \$int1 X \$int2 = " . ($int1 * $int2); //divide echo "<br /> \$int2 divided / by \$int1 = " . ($int2 / $int1); //remainder or modulus operator echo "<br /> \$int2 remainder of \$int1 = " . ($int2 % $int1); ?> Quote Link to comment https://forums.phpfreaks.com/topic/239107-super-easy-problem-involving-simple-math-functions/#findComment-1228539 Share on other sites More sharing options...
silverglade Posted June 12, 2011 Author Share Posted June 12, 2011 thank you so much spiderwell and Pikachu2000. This PHP for dummies book is not too good. In my book they were not inside parenthesis. It was strange that it worked for some without the parenthesis, but with + and - it didn't . So when I added () to the + and - terms, it worked!! You both preserved my SANITY!! LOL. so thanks. Quote Link to comment https://forums.phpfreaks.com/topic/239107-super-easy-problem-involving-simple-math-functions/#findComment-1228541 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.