ballhogjoni Posted December 18, 2008 Share Posted December 18, 2008 How can I find out if a number is positive or negative? Quote Link to comment https://forums.phpfreaks.com/topic/137588-find-whether-an-int-is-positive-or-negative/ Share on other sites More sharing options...
DarkWater Posted December 18, 2008 Share Posted December 18, 2008 <?php $int = -19; if ($int < 0) { echo "neg"; } else { echo "pos"; } Quote Link to comment https://forums.phpfreaks.com/topic/137588-find-whether-an-int-is-positive-or-negative/#findComment-719134 Share on other sites More sharing options...
.josh Posted December 18, 2008 Share Posted December 18, 2008 That doesn't exactly account for if $int doesn't exist, though. If $int doesn't exist, it will evaluate true, or 0, and echo "pos". You'd have to wrap an if ($int) or if (isset($int)) or something around that. edited for clarification. I posted an example similar to darkwater's and based my explanation off it. But since he posted an example, I changed it to base it off of his example. Quote Link to comment https://forums.phpfreaks.com/topic/137588-find-whether-an-int-is-positive-or-negative/#findComment-719137 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.