This question already has an answer here:
- Problem with json_encode() 4 answers
I am having a problem using json_encode to generate a json encoded string from an array.
The section of the array in question looks like this
RatingDistribution (Array, 11 elements)
0 (Array, 1 element)
0 (String, 3 characters ) 4.5
1 (Array, 1 element)
1 (String, 4 characters ) 11.9
2 (Array, 1 element)
But produces this in the string:
"RatingDistribution":[["4.5"],{"1":"11.9"},
I would expect this:
"RatingDistribution":[{"0":"4.5"},{"1":"11.9"},
All I'm doing is this:
$result = json_encode($array);
Have I done something wrong or do I need more code to ensure the 0 key is present?
Cheers Andy