FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » JSON variabiles
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
JSON variabiles [message #178877] Fri, 17 August 2012 14:54 Go to next message
Sarah is currently offline  Sarah
Messages: 30
Registered: December 2010
Karma: 0
Member
Hi, I use this code

$data['code'][] = $result;
Header('Content-type: application/json');
echo json_encode($data);
exit;

For return a value using JSON.

{"code":["202"]}

(1 value returned)

Now I would like to return not only 1 value but 2 (2 variables)



How can I return another value? First value $result, second value $second

$data['code'][] = $result; //questa è la prima variabile passata
$data['code'][] = ???? //How can I pass also $second variabile for return 2 values in JSON?

Thanks
Re: JSON variabiles [message #178878 is a reply to message #178877] Fri, 17 August 2012 16:12 Go to previous messageGo to next message
simgish is currently offline  simgish
Messages: 3
Registered: August 2012
Karma: 0
Junior Member
On Friday, August 17, 2012 10:54:26 AM UTC-4, dand...@gmail.com wrote:
> Hi, I use this code
>
>
>
> $data['code'][] = $result;
>
> Header('Content-type: application/json');
>
> echo json_encode($data);
>
> exit;
>
>
>
> For return a value using JSON.
>
>
>
> {"code":["202"]}
>
>
>
> (1 value returned)
>
>
>
> Now I would like to return not only 1 value but 2 (2 variables)
>
>
>
>
>
>
>
> How can I return another value? First value $result, second value $second
>
>
>
> $data['code'][] = $result; //questa è la prima variabile passata
>
> $data['code'][] = ???? //How can I pass also $second variabile for return 2 values in JSON?
>
>
>
> Thanks

If you're wanting the keys to both be "code", assign the array like this:

$data[]['code'] = '123';
$data[]['code'] = '456';


That will give you:

[Object { code="123"}, Object { code="456"}]

On Friday, August 17, 2012 10:54:26 AM UTC-4, dand...@gmail.com wrote:
> Hi, I use this code
>
>
>
> $data['code'][] = $result;
>
> Header('Content-type: application/json');
>
> echo json_encode($data);
>
> exit;
>
>
>
> For return a value using JSON.
>
>
>
> {"code":["202"]}
>
>
>
> (1 value returned)
>
>
>
> Now I would like to return not only 1 value but 2 (2 variables)
>
>
>
>
>
>
>
> How can I return another value? First value $result, second value $second
>
>
>
> $data['code'][] = $result; //questa è la prima variabile passata
>
> $data['code'][] = ???? //How can I pass also $second variabile for return 2 values in JSON?
>
>
>
> Thanks



On Friday, August 17, 2012 10:54:26 AM UTC-4, dand...@gmail.com wrote:
> Hi, I use this code
>
>
>
> $data['code'][] = $result;
>
> Header('Content-type: application/json');
>
> echo json_encode($data);
>
> exit;
>
>
>
> For return a value using JSON.
>
>
>
> {"code":["202"]}
>
>
>
> (1 value returned)
>
>
>
> Now I would like to return not only 1 value but 2 (2 variables)
>
>
>
>
>
>
>
> How can I return another value? First value $result, second value $second
>
>
>
> $data['code'][] = $result; //questa è la prima variabile passata
>
> $data['code'][] = ???? //How can I pass also $second variabile for return 2 values in JSON?
>
>
>
> Thanks



On Friday, August 17, 2012 10:54:26 AM UTC-4, dand...@gmail.com wrote:
> Hi, I use this code
>
>
>
> $data['code'][] = $result;
>
> Header('Content-type: application/json');
>
> echo json_encode($data);
>
> exit;
>
>
>
> For return a value using JSON.
>
>
>
> {"code":["202"]}
>
>
>
> (1 value returned)
>
>
>
> Now I would like to return not only 1 value but 2 (2 variables)
>
>
>
>
>
>
>
> How can I return another value? First value $result, second value $second
>
>
>
> $data['code'][] = $result; //questa è la prima variabile passata
>
> $data['code'][] = ???? //How can I pass also $second variabile for return 2 values in JSON?
>
>
>
> Thanks



On Friday, August 17, 2012 10:54:26 AM UTC-4, dand...@gmail.com wrote:
> Hi, I use this code
>
>
>
> $data['code'][] = $result;
>
> Header('Content-type: application/json');
>
> echo json_encode($data);
>
> exit;
>
>
>
> For return a value using JSON.
>
>
>
> {"code":["202"]}
>
>
>
> (1 value returned)
>
>
>
> Now I would like to return not only 1 value but 2 (2 variables)
>
>
>
>
>
>
>
> How can I return another value? First value $result, second value $second
>
>
>
> $data['code'][] = $result; //questa è la prima variabile passata
>
> $data['code'][] = ???? //How can I pass also $second variabile for return 2 values in JSON?
>
>
>
> Thanks

If you're wanting the keys to both be "code", build the array like this:

$data[]['code'] = '123';
$data[]['code'] = '456';


That will give you:

[Object { code="123"}, Object { code="456"}]
Re: JSON variabiles [message #178879 is a reply to message #178877] Fri, 17 August 2012 16:27 Go to previous message
simgish is currently offline  simgish
Messages: 3
Registered: August 2012
Karma: 0
Junior Member
On Friday, August 17, 2012 10:54:26 AM UTC-4, dand...@gmail.com wrote:
> Hi, I use this code
>
>
>
> $data['code'][] = $result;
>
> Header('Content-type: application/json');
>
> echo json_encode($data);
>
> exit;
>
>
>
> For return a value using JSON.
>
>
>
> {"code":["202"]}
>
>
>
> (1 value returned)
>
>
>
> Now I would like to return not only 1 value but 2 (2 variables)
>
>
>
>
>
>
>
> How can I return another value? First value $result, second value $second
>
>
>
> $data['code'][] = $result; //questa è la prima variabile passata
>
> $data['code'][] = ???? //How can I pass also $second variabile for return 2 values in JSON?
>
>
>
> Thanks

$data['code'][] = '123';
$data['code'][] = '456';

That will give you:

{"code":["123","456"]}
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Free service to allow large file upload in PHP forms
Next Topic: PHP Session Variable
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 21 22:03:09 GMT 2024

Total time taken to generate the page: 0.02681 seconds