wolfcry Posted January 7, 2012 Share Posted January 7, 2012 Hey all, I could have sworn I did it before but looking through my repository, as well as searching online, I cannot find an answer to this. Basically, what I'm doing is adding calculations the user inputs, however, if the calculation comes up as "0" (i.e. 4 + 4 - 8 = 0 etc.), it not only kills the script (believing it to be FALSE), but it doesn't retain as the numeric value of "0" (even though I know, mathematically zero has no numeric value). I've tried a few things, including modulus but it's not clicking for some reason. Also, I forgot to add this tidbit in the original post, but I am using eval() to perform the calculations if that helps any. Quote Link to comment https://forums.phpfreaks.com/topic/254534-i-may-be-off-my-rocker-but-is-there-a-way-to-keep-the-value-of-zero/ Share on other sites More sharing options...
Andy-H Posted January 7, 2012 Share Posted January 7, 2012 $var = 0; if ( $var !== false ) echo 'true'; "true" will be outputted as it uses !==, !== (and ===) are strict comparison operators and will only return true if the values do not/do (respectively) match by both type and value. As for outputting 0, cast to a string should work I think. echo (string)$var; Quote Link to comment https://forums.phpfreaks.com/topic/254534-i-may-be-off-my-rocker-but-is-there-a-way-to-keep-the-value-of-zero/#findComment-1305222 Share on other sites More sharing options...
wolfcry Posted January 7, 2012 Author Share Posted January 7, 2012 Thanks Andy, I'll give that a shot. Quote Link to comment https://forums.phpfreaks.com/topic/254534-i-may-be-off-my-rocker-but-is-there-a-way-to-keep-the-value-of-zero/#findComment-1305223 Share on other sites More sharing options...
wolfcry Posted January 7, 2012 Author Share Posted January 7, 2012 Works like a charm. Thanks Andy Quote Link to comment https://forums.phpfreaks.com/topic/254534-i-may-be-off-my-rocker-but-is-there-a-way-to-keep-the-value-of-zero/#findComment-1305230 Share on other sites More sharing options...
Andy-H Posted January 7, 2012 Share Posted January 7, 2012 No problem mate. Quote Link to comment https://forums.phpfreaks.com/topic/254534-i-may-be-off-my-rocker-but-is-there-a-way-to-keep-the-value-of-zero/#findComment-1305232 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.