Returning PHP Multi-Dimension Array to Javascript/AJAX

Posted by GregH on Stack Overflow See other posts from Stack Overflow or by GregH
Published on 2010-06-07T01:29:56Z Indexed on 2010/06/07 1:32 UTC
Read the original article Hit count: 207

Filed under:
|
|
|

My understanding is that in order to return a complex PHP variable to Javascript, it should be done via AJAX and json_encode. Could somebody give me an actual example (both PHP and Javascript code) of this? Lets say we have the two-dim array in PHP:

$twoDArr = array( array('Greg', 44, 'Owner'),
                  array('Joe', 23, 'Renter'),
                  array('Susan', 39, 'Owner'),
                  array('John', 32, 'Renter)
                );

How would we return this to an analogous two dimensional array in javascript using json_encode?

© Stack Overflow or respective owner

Related posts about php

Related posts about JavaScript