This is a continuation of the nested query thing I posted to the list a while
back. I was finally able to output a nested unordered array that worked out
well, but scope-creep has come in the door and I have to change gears.
I have a project where I have multiple queries and each query uses the results
from the previous query to get it's results. I need to do one of two things,
either out put a multidimensional array that I can use json_encode() on or I
have to format the output from the queries as a JSON string. The resulting JSON
will be used by a JavaScript widget and must be formed correctly. I created the
following array by hand:
$userList = array("John" => array(
"email" => "[email protected]",
"website" => "www.john.com",
"age" => "22",
"password" => "pass",
"description" => array(
"hair" => "blonde",
"eyes" => "blue",
"build" => "medium"
)),
"Anna" => array(
"email" => "[email protected]",
"website" => "www.anna.com",
"age" => "24",
"password" => "pass",
"description" => array(
"hair" => "brunette",
"eyes" => "hazel",
"build" => "petite"
)
));
I ran it through json_encode() and got the following output
{"John":{"email":"[email protected]","website":"www.john.com","age":"22","password":"pass","description":{"hair":"blonde","eyes":"blue","build":"medium"}},"Anna":{"email":"[email protected]","website":"www.anna.com","age":"24","password":"pass","description":{"hair":"brunette","eyes":"hazel","build":"petite"}}}
jslint.com verifies this as good JSON (although I thought there had to be
square brackets around child arrays).
If you were me would you just generate the JSON? If not what is he best way to
output an array that will nest properly for each subsequent query?
Thanks for any insight!