so I am a total php/javascript noob.
I'm trying load a full php array into a javascript array. I wrote this for Javascript:
var names = new Array();
for(var i = 0; i < 48; i++) {
names[i] = "<?php echo giveJS() ?>";
}
And this for php
static $counter = 0;
function giveJS() {
global $names;
global $counter;
$counter++;
return $names[$counter];
}
I already checked if the php array is correctly filled with data. When I write a output line in javascript, like
document.write(names[10]);
it only gives me the first entry in the php array so it seems like everytime the for loop is repeated its initialising the php file from scratch and so setting the counter to 0. How can i fix that?
static $counter = 0;
(inside the function) or you use a global variable.