Jump to content

I may be off my rocker, but is there a way to keep the value of zero?


wolfcry

Recommended Posts

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.

$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; 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.