My overall goal was to pass an array of numbers from php to js. I saw solutions elsewhere to just put within the javascript and so I have been trying that. However, I keep getting an error "Unexpected Token ?" when I add in the line with php. I have checked that $ztable is in fact the variable I want and that it does properly exist. Below are three different examples of what I have tried and all of them returned the same error. I have tried a couple other methods of getting the variable from php to the javascript as well but none seemed to worked right for me. If there is something wrong with the code I have written please let me know, or if there is another simple method of transferring the variable I would love to hear it. With my application the variable is only being passed once so speed is not an issue, nor is security (for different reasons).
<script>
ztable = new array(<?php echo json_encode($ztable); ?>);
....other unrelated code.....
</script>
<script>
var ztable = <?php echo json_encode($ztable); ?>;
....other unrelated code.....
</script>
<script>
var ztable = <?php echo $ztable; ?>;
....other unrelated code.....
</script>
edit: I am not using jQuery, and my php code is pretty simple, it just generates an array of numbers based on the users input along the lines of
$ztable = [0.001, 0.003, 0.006, 0.01, 0.02, 0.04, 0.07, 0.11, 0.16, 0.23, 0.31, 0.4, 0.5, 0.4, 0.31, 0.23, 0.16, 0.11, 0.07, 0.04, 0.02, 0.01, 0.006, 0.003, 0.001];