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

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -