Re: JSON variabiles [message #178878 is a reply to message #178877] |
Fri, 17 August 2012 16:12 |
simgish
Messages: 3 Registered: August 2012
Karma:
|
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"}]
|
|
|