PHP - 复杂的字符串到多维数组

时间:2012-07-06 13:43:49

标签: php arrays multidimensional-array

我有一个看起来像的字符串:

["DZ_Backpack_EP1",[["M4A1"],["M16A2]],[["ItemWaterbottle","FoodSteakCooked","ItemPainkiller","ItemSodaPepsi","ItemBloodbag","ItemMorphine","ItemEpinephrine","ItemBandage"],[1,2,1,1,1,1,1,1]]]

Ant我需要获取此数组:

DZ_Backpack_EP1 = array(
                 ['weapons'] => array (
                             [0] => 'M4A1',
                             [1] => 'M16A2' 
                             ),
                 ['items'] => array (
                             ['ItemsList'] => array ( 
                                 [0] = > 'ItemWaterbottle',
                                 [1] = > 'FoodSteakCooked',
                                 [2] = > 'ItemPainkiller',
                                 [3] = > 'ItemSodaPepsi',
                                 [4] = > 'ItemBloodbag',
                                 [5] = > 'ItemMorphine',
                                 [6] = > 'ItemEpinephrine',
                                 [7] = > 'ItemBandage'),
                             ['ItemsCount'] => array ( 
                                 [0] = > 'ItemWaterbottle',
                                 [1] = > 'FoodSteakCooked',
                                 [2] = > 'ItemPainkiller',
                                 [3] = > 'ItemSodaPepsi',
                                 [4] = > 'ItemBloodbag',
                                 [5] = > 'ItemMorphine',
                                 [6] = > 'ItemEpinephrine',
                                 [7] = > 'ItemBandage'
                                 )
                             )
                 )

我尝试编辑此示例PHP - string to multidimensional array,但没有运气。 有什么想法吗?

1 个答案:

答案 0 :(得分:6)

您似乎只需要json_decode