I want to push a php variable to javascript. The code is below but does not seem to work. Can anyone show me how to do this?
ticks.push(<?php echo json_encode($new); ?>);
Is this what you're looking for?
ticks.push(JSON.parse('<?= json_encode($new); ?>'));
Or broken down:
var json = '<?= json_encode($new); ?>';
var obj = JSON.parse(json);
ticks.push(obj)
also addressed in this issue:
can you try this
var tricks = [
<?php
foreach ($new as $n) {
echo '"'.$n'", ';
}
?>
];
echo json_encode($new);produce? What's the resulting line of javascript?