This question already has an answer here:(这个问题已经在这里有了答案:)
How do I pass variables and data from PHP to JavaScript?(如何将变量和数据从PHP传递到JavaScript?) 19 answers(19个答案)I am trying to get a PHP array variable into a JavaScript variable.(我正在尝试将PHP数组变量转换为JavaScript变量。)
This is my code:(这是我的代码:)<html>
<head>
<script type="text/javascript">
function drawChart(row,day,week,month,date)
{
// Some code...
}
</script>
</head>
<body>
<?php
for($counter = 0; $counter<count($au); $counter++)
{
switch($au[$counter]->id)
{
case pageID.'/insights/page_active_users/day':
$day[] = $au[$counter]->value;
break;
case pageID.'/insights/page_active_users/week':
$week[] = $au[$counter]->value;
break;
case pageID.'/insights/page_active_users/month':
$month[] = $au[$counter]->value;
break;
}
}
?>
<script>
drawChart(600/50, '<?php echo $day; ?>', '<?php echo $week; ?>', '<?php echo $month; ?>', '<?php echo createDatesArray(cal_days_in_month(CAL_GREGORIAN, date('m',strtotime('-1 day')), date('Y',strtotime('-1 day')))); ?>');
</script>
</body>
</html>
I can't get value of the PHP array.(我无法获得PHP数组的价值。)
How do I fix this problem?(我该如何解决这个问题?)
ask by Chirayu translate from so