How to have PHP boolean FALSE to be output as FALSE only

php

Solution

echo '<script type="text/javascript">
          var a = '.($a?"true":"false").';
          var b = '.($b?"true":"false").';
      </script>';

I suppose, You cant simply echo true/false to get the word, You need to convert it to string.

Problem

I am setting a PHP variable's value as false. Then after some processing I am outputting some JavaScript variables in a script. This is the code ``` $a = true; $b = false; echo '<script type="text/javascript"> var a = '.$a.'; var b = '.$b.'; </script>'; ``` When the script finishes I get this output: ``` var a = 1; var b = ; ``` So I get syntax error in JavaScript. Now the question is, how to have those values as true boolean values in JavaScript as well? Intended output: ``` var a = true; var b = false; ``` I don't want string like `'true'` or `'false'`...or 1 and 0, but boolean `true` and `false` only. Any help regarding this, also with some explanation as to why PHP behaves this way?

Original source