我有一个数组:
$myAssocArray = array(
['fred','tyson',23],
['collins', 'white', 54],
['mary', 'frost', 46]
);当我对阵列执行json_encode操作时:
$jsonString = json_encode($myAssocArray);
echo $jsonString;我得到了:
[['fred','tyson',23],['collins', 'white', 54],['mary', 'frost', 46]]但我希望得到以下结果:
[{0:'fred',1:'tyson',2: 23},{0:'collins', 1:'white', 2: 54},{0:'mary', 1:'frost',2: 46}]发布于 2018-04-08 07:08:06
找到了一个解决方案,我必须将嵌套数组转换为对象
(object) $myDynamicNestedArray;PHP json_encode - JSON_FORCE_OBJECT mixed object and array output
https://stackoverflow.com/questions/49712771
复制相似问题