echo - Why won't PHP print 0 value? -
i have been making fahrenheit celsius (and vise versa) calculator. of works great, when try calculate 32 fahrenheit celsius it's supposed 0, instead displays nothing. not understand why not echo 0 values.
here code:
<?php // celsius , fahrenheit converter // programmed clyde cammarata $error = '<font color="red">error.</font>'; function tempconvert($temptype, $givenvalue){ if ($temptype == 'fahrenheit') { $celsius = 5/9*($givenvalue-32); echo $celsius; } elseif ($temptype == 'celsius') { $fahrenheit = $givenvalue*9/5+32; echo $fahrenheit; } else { die($error); exit(); } } tempconvert('fahrenheit', '50'); ?>
looks $celcius
has value 0 (int type) not "0" (string type), wont echoed because php read false (0 = false, 1 = true).
try change code
echo $celcius;
to
echo $celcius."";
or
echo (string) $celcius;
it convert variable string
Comments
Post a Comment