I have a two-dimensional php array, $phpar, in which both dimensions are indexed (0,1,2,...), and all values are plain text. Within a JavaScript function, I want to convert this array into a two-dimensional JavaScript array. I know the following code doesn't work, but it illustrates what I want to do.
jsfunction() {
var jsarray = new Array();
jsarray = <?php json_encode($phpar); ?>;
}
If the returned value is something other than a regular js array, like a JSON string, I need some help parsing that into what I want, please.
$phpar
really contains a two-dimensional array. (Except there's no need for the= new Array()
part at all, you're just creating an array to throw it away on the next line). So what you want to do, if this isn't working, is look at what the browser receives for it, and update the PHP variable so it really contains a two-dimensional array. – T.J. Crowder Aug 25 '13 at 17:29JSON.parse
? Is it me missing something, or is it plain hogwash? I'm just making sure I'm not the only one on this. O.o – Christian Aug 25 '13 at 19:59json_encode
the stuff!! – Christian Aug 25 '13 at 20:03