Selacius Posted June 25, 2010 Share Posted June 25, 2010 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 More sharing options...
Synook Posted June 25, 2010 Share Posted June 25, 2010 Did you check what the output was? You may find it easier to use JSON. Link to comment Share on other sites More sharing options...
Selacius Posted June 25, 2010 Author Share Posted June 25, 2010 Nothing is outputted. The screen does not display anything like it should. Link to comment Share on other sites More sharing options...
Synook Posted June 25, 2010 Share Posted June 25, 2010 I mean, the JavaScript code that was output. Link to comment Share on other sites More sharing options...
wirehopper Posted June 25, 2010 Share Posted June 25, 2010 javascript uses integers for array indicies Link to comment Share on other sites More sharing options...
Selacius Posted June 25, 2010 Author Share Posted June 25, 2010 Oh, I don't know what the javascript code that was outputted. How could I find that?wirehopper, how is that going to help me? Link to comment Share on other sites More sharing options...
Synook Posted June 25, 2010 Share Posted June 25, 2010 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.