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

Viewed 626

Possible Duplicate:
transfer a Variable from php to js

This might seem trivial. 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?

6 Answers
Related