PDA

View Full Version : php: json_encode



indeo
2 Apr 2011, 1:40 PM
How can i proper encode array like this:
<?php

$arr[1]['name']='Ralf';
$arr[1]['age']=28;
$arr[2]['name']='Adam';
$arr[2]['age']=23;

?>

into json using json_encode? The php returns code:

{"1":{"name":"Ralf","age":28},"2":{"name":"Adam","age":23}}
but i need something like this:

{{"name":"Ralf","age":28},{"name":"Adam","age":23}}
I don't need sequence "1":{....

steffenk
2 Apr 2011, 3:42 PM
$arr = array();

$arr[] = array(
'name' => 'Ralf',
'age' => 28
);
$arr[] = array(
'name' => 'Adam',
'age' => 23
);

return json_encode($arr);