问题
I have to output $var1
. To do that, I return results by using
sendJson($var1);
And this is working fine for me. Now I want to pass two variables $var1
and $var2
using sendJson();
. Is it possible?
回答1:
Put them all inside an array:
sendJson(array($var1, $var2));
Or name them if you don't want to do it index-based:
sendJson(array('var1' => $var1, 'var2' => $var2))
回答2:
name your array keys:
echo json_encode( array (
'messages' => array(
'peter' => 'Hello',
'john' => 'Hi to you too'
),
'users' => array (
'peter', 'john'
)
));
and then access them like this:
resp.messages.peter
resp.messages.john
or
resp.users[0], resp.users[1].... etc.
来源:https://stackoverflow.com/questions/13910024/return-multiple-json-results