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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.