php将字符串转化成二维关联数组
我有一个字符串像是"[{"name":"琥珀珍珠奶茶(中杯)","price":"10","gid":4},{"name":"香柠咖啡(大杯)","price":"14"...
我有一个字符串像是"[{"name":"琥珀珍珠奶茶(中杯)","price":"10","gid":4},{"name":"香柠咖啡(大杯)","price":"14","gid":5}]"这样的,然后转换成
[
['name' => '琥珀珍珠奶茶(中杯)', 'price' => 10,'gid'=>4],
['name' => '香柠咖啡(大杯)', 'price' => 0,'gid'=>5]
]实在无法解决,请教大神们如何操作? 展开
[
['name' => '琥珀珍珠奶茶(中杯)', 'price' => 10,'gid'=>4],
['name' => '香柠咖啡(大杯)', 'price' => 0,'gid'=>5]
]实在无法解决,请教大神们如何操作? 展开
展开全部
$json = '[{"name":"琥珀珍珠奶茶(中杯)","price":"10","gid":4},{"name":"香柠咖啡(大杯)","price":"14","gid":5}]';
$array = json_decode($json, true);
print_r($array); //Array ( [0] => Array ( [name] => 琥珀珍珠奶茶(中杯) [price] => 10 [gid] => 4 ) [1] => Array ( [name] => 香柠咖啡(大杯) [price] => 14 [gid] => 5 ) )
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询