Page 1 of 1

detecting difference between 0 and null

Posted: Sun Feb 19, 2006 1:51 pm
by Benjamin
Hi there, I wrote this code for a drop down menu to select a minute. When it creates the drop down menu, 0 is selected even though the $minute variable is null. I tried changing the comparison operator to === but that didn't work either. I know this is probably simple but I forgot how to do it.

Code: Select all

if (($minute == '') and ($minute == null)) { echo '<option selected value=""></option>' . "\n"; }
for ($i = 0; $i <= 60; $i++) {
  if ($minute == $i) { echo ' <option selected value="' . $i . '">' . $i . '</option>' . "\n";
  } else {
  echo '<option value="' . $i . '">' . $i . '</option>' . "\n";
  }
}

Posted: Sun Feb 19, 2006 1:58 pm
by feyd

Code: Select all

if ($minute === null) { echo '<option selected value=""></option>' . "\n"; }

Posted: Sun Feb 19, 2006 2:29 pm
by Benjamin
Thank feyd I was close, I was using the '' instead of null.