Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!

 



Forgot your password?
typodupeerror
×
PHP

Journal tmhsiao's Journal: null == 0...

Looking at the following code:

if ($foo == 1) {
  echo "Foo is 1";
}
elseif ($foo == 0) {
  echo "Foo is 0";
}

If $foo is not defined (as in the case of, say, an unposted $_POST variable), $foo == 0 evaluates as true.

All null values equal 0 apparently, forcing any specific zero-check to look as follows:

if ($foo == 1) {
  echo "Foo is 1";
}
elseif (($foo == 0) && (is_numeric($foo))) {
  echo "Foo is 0";
}

Sometimes I hate this language.

This discussion has been archived. No new comments can be posted.

null == 0...

Comments Filter:

So you think that money is the root of all evil. Have you ever asked what is the root of money? -- Ayn Rand

Working...