I explored a bunch of related questions but to no avail.
I use json_encode
to pass on a PHP variable to JS and it works fine.
<?php echo json_encode($datasets[0]);?>);
But when I try to do the same thing inside a JS for
loop using the index of the loop it only picks up null
.
How can I use the the index of the PHP array $datasets[]
inside a JS for
loop?
const DT = [];
for (let i = 0; i < 10; i++) {
DT.push(<?php echo json_encode($datasets[i]);?>);
};