I have an array:
$myAssocArray = array(
['fred','tyson',23],
['collins', 'white', 54],
['mary', 'frost', 46]
);
When I json_encode
the array:
$jsonString = json_encode($myAssocArray);
echo $jsonString;
I get:
[['fred','tyson',23],['collins', 'white', 54],['mary', 'frost', 46]]
But I would like the following result:
[{0:'fred',1:'tyson',2: 23},{0:'collins', 1:'white', 2: 54},{0:'mary', 1:'frost',2: 46}]
JSON_FORCE_OBJECT
to the second argument ofjson_encode
but that will not result in the exact value that you want.>
) are for, well, quotes. They're not for emphasis. See stackoverflow.com/editing-help"[{'fred','tyson',23},{'collins', 'white', 54},{'mary', 'frost', 46}]"
.json_encode()
.