I have a php variable called $usershours
that contains an array, and I want to echo it inside Javascript code. How do I do that?
I tried This, but it didn't work:
$usershours = "
data.addRow([ new Date(2012,4,1),50119]).+'<br>+'.
data.addRow([ new Date(2012,4,2),242575])";
<script type="text/javascript">
document.write($arrayholder);
</script>
I want the output to be like this:
data.addRow([ new Date(2012,4,1),50119])
data.addRow([ new Date(2012,4,2),242575])
PS - I need this format because This is the format that Google charts API accept to render charts correctly.
<?php echo $userhours ?>
– locrizak Aug 22 '12 at 2:04$usershours = "data.addRow([ new Date(2012,4,1),50119]) data.addRow([ new Date(2012,4,2),242575]) "; echo $usersHours;
is the output you asked for. You will not see anything on the screen, as the resulting JavaScript just calls a function on thedata
object. If there is more you are expecting, you need to write a different question. – Dan Grossman Aug 22 '12 at 2:15<script>
and</script>
tags. – Dan Grossman Aug 22 '12 at 2:18<script>
tags around it:?><script>data.addRow([ new Date(2012,4,1),50119]) data.addRow([ new Date(2012,4,2),242575])</script><?php
– meagar Aug 22 '12 at 2:34