稍后在javascript和不同文件中使用PHP变量

I'm confused on the best way to go about this. I have a file that includes both a php and javascript file. The PHP file grabs a variable from the database. I'd like to use that variable in the js. I thought I could do it like this:

PHP:

$string = implode($blocked_days,"][");
$string = "[ [". $string . "] ]";
echo "<script type='text/javascript'> window.closedDays = ". $string .";</script>";

Javascript:

              function customSchedule(date) {

            //  alert(window.closedDays);

              var days = new Array();
              days["Sunday"] = 0;
              days["Monday"] = 1;
              days["Tuesday"] = 2;
              days["Wednesday"] = 3;
              days["Thursday"] = 4;
              days["Friday"] = 5;
              days["Saturday"] = 6;

              var fetchedClosedDays = window.closedDays;
              var closedDays = new Array();

              $.each(fetchedClosedDays, function(index, value){
                     closedDays.push([days[value]]);
                     });

window.closedDays returns undefined. What's the best way to get the PHP variable $string to use for the JS?

Following should give you JS object, so you dont have to worry about imploding and setting the $string.

echo "<script type='text/javascript'> window.closedDays = JSON.parse('". json_encode($string) ."');</script>";

try to make Ajax call to the server and get needded data