lanu Posted December 24, 2011 Share Posted December 24, 2011 <?php if ($beyondportal % 26 == 0 || $beyondportal == 0){ ?> MY CONTENT <?php } ; ?> This code compares my variable $beyondportal and if it is a multiple of 26 counting up from 0, it prints my content. This is great but sometimes the number comes up a negative that is a multiple counting down from 0 like -26, -52, etc.. if I could do the opposite of a modulus I would think it would work but I'm not sure how to in php. any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/253787-dealing-with-negative-numbers/ Share on other sites More sharing options...
kicken Posted December 24, 2011 Share Posted December 24, 2011 Just use abs() to make the number non-negative. Quote Link to comment https://forums.phpfreaks.com/topic/253787-dealing-with-negative-numbers/#findComment-1301077 Share on other sites More sharing options...
Pikachu2000 Posted December 24, 2011 Share Posted December 24, 2011 If what you're saying is that you want modulus to work with a negative, why not use the absolute value? Quote Link to comment https://forums.phpfreaks.com/topic/253787-dealing-with-negative-numbers/#findComment-1301079 Share on other sites More sharing options...
lanu Posted December 24, 2011 Author Share Posted December 24, 2011 how do you use abs() in this context? Quote Link to comment https://forums.phpfreaks.com/topic/253787-dealing-with-negative-numbers/#findComment-1301080 Share on other sites More sharing options...
lanu Posted December 24, 2011 Author Share Posted December 24, 2011 This is my best guess. I'm really not clear what abs() does. <?php if ($beyondportal % 26 == 0 || $beyondportal == 0 || $beyondportal abs(26) == 0){ ?> MY CONTENT <?php } ; ?> Quote Link to comment https://forums.phpfreaks.com/topic/253787-dealing-with-negative-numbers/#findComment-1301081 Share on other sites More sharing options...
kicken Posted December 24, 2011 Share Posted December 24, 2011 <?php if (abs($beyondportal) % 26 == 0 || $beyondportal == 0){ ?> MY CONTENT <?php } ; ?> Quote Link to comment https://forums.phpfreaks.com/topic/253787-dealing-with-negative-numbers/#findComment-1301088 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.