| |
(See also Chapter 6 of the manual, Type Juggling)
I was having difficulty persuading the Forms include file (11 Nov) to include any value for VALUE if it was set to 0 (zero). The snippet of PHP was:
if($val) $ret.=" VALUE='$val'";
If $val was set to zero the test would fail, even though I wanted " VALUE='0'" added. Next I tried:
if($val!=null) $ret.=" VALUE='$val'";
and this appeared to work, then did not! The reason is that I tested with $val="0" (string value ASCII 48) which worked, but $val=0 did not. Useful if it was necessary to differentiate between the two, of course. The following did work:
if($val!==null) $ret.=" VALUE='$val'";
If now it was necessary for a $val to NOT be included it was necessary to explicitly set the parameter to null - even a value of "" (a null string) passed the test, giving:
$ret.=" VALUE=''"; |