title: Pass a PHP array to a JavaScript function
body: <p>I am trying to get a PHP array variable into a JavaScript variable.</p>
  
  <p>This is my code:</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;script type="text/javascript"&gt;
                function drawChart(row,day,week,month,date)
                {
                    // Some code...
                }
          &lt;/script&gt;
      &lt;/head&gt;
  
      &lt;body&gt;
          &lt;?php
              for($counter = 0; $counter&lt;count($au); $counter++)
              {
                  switch($au[$counter]-&gt;id)
                  {
                      case pageID.'/insights/page_active_users/day':
                          $day[] = $au[$counter]-&gt;value;
                      break;
                      case pageID.'/insights/page_active_users/week':
                          $week[] = $au[$counter]-&gt;value;
                      break;
                      case pageID.'/insights/page_active_users/month':
                          $month[] = $au[$counter]-&gt;value;
                      break;
                  }
              }
          ?&gt;
          &lt;script&gt;
              drawChart(600/50, '&lt;?php echo $day; ?&gt;', '&lt;?php echo $week; ?&gt;', '&lt;?php echo $month; ?&gt;', '&lt;?php echo createDatesArray(cal_days_in_month(CAL_GREGORIAN, date('m',strtotime('-1 day')), date('Y',strtotime('-1 day')))); ?&gt;');
          &lt;/script&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I can't get value of the PHP array.</p>
  
  <p>How do I fix this problem?</p>