Jump to content

Filling a Javascript array via php


Selacius

Recommended Posts

I am trying to populate a JS array using php. here is the JS code.

maps['castle_1']['map'] = new Array(new Array("wall","wall","wall","wall","wall","wall","wall","wall"),new Array("D"," "," "," "," "," "," "," ")	

And here is my attempt at mimicing it via PHP:

maps['castle_1']['map'] = new Array(		<? 	$xc = count ($map);			$yc = count ($map[0]);			for ($y=0;$y<=$yc;$y++) {?>				new Array(\" <?				for ($x=0;$x<=$xc;$x++) {					$map[$x][$y]?>\",<?}),}<?)

I am not sure why its not working. Basically I am pulling the map from the database and want to enter it into this javascript array.

Link to comment
Share on other sites

Did you check what the output was? You may find it easier to use JSON.

Link to comment
Share on other sites

Just go "view source". I've just noticed, you may not be echoing out everything you need here:

for ($x=0;$x<=$xc;$x++) {					$map[$x][$y]?>\",<?}),}<?)

Also, there's a syntax error. Do you have error reporting turned on?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...