I am making a php file which will return json data to javascript file. Currently it only returns the last json object and ignores the rest of them. Here is my php code
$arr = array(
"cartId" => 456186,
"lastModified" => "Tue, 19 Jan 2010 03:14:07 GMT",
"items" => array(
15642,
45616,
54984,
45751
),
"cartId" => 456187,
"lastModified" => "Tue, 20 Jan 2010 04:14:07 GMT",
"items" => array(
'item' => 15643,
'item' => 45617,
'item' => 54985,
'item' => 45752
)
);
echo json_encode($arr);
above code returns following
{"cartId":456187,"lastModified":"Tue, 20 Jan 2010 04:14:07 GMT","items":{"item":45752}}
How can I resolve this issue?
The first elements are being overwritten with the second elements as their keys are same. Same with the
itemsarray in the second item.Try