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
Return to the default flat view Create a new topic Submit Reply
Re: JSON variabiles [message #178878 is a reply to message #178877] Fri, 17 August 2012 16:12 Go to previous messageGo to previous message
simgish is currently offline  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"}]
[Message index]
 
Read Message
Read Message
Read Message
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: Sun Nov 24 11:31:30 GMT 2024

Total time taken to generate the page: 0.05024 seconds