我在php中打印出了应该是多维数组的内容,但却看到了这一点。当我尝试访问$array['order_item']['sku']
时,它会抛出错误。如何将其转换为正确的多维数组?
Array
(
[order_item] => [{"name":"Product","sku":"14b6c7e2f838fd356","description":"Product Standard Download","price":"76.0000","qty":1,"tax":0}]
[customer] => {"first_name":"Johny","last_name":"Smith","email":"johnyzc@gmail.com"}
)
答案 0 :(得分:1)
尝试这个
$array = array(
'order_item' => '[{"name":"Product","sku":"14b6c7e2f838fd356","description":"Product Standard Download","price":"76.0000","qty":1,"tax":0}]',
'customer' => '{"first_name":"Johny","last_name":"Smith","email":"johnyzc@gmail.com"}'
);
foreach ($array as $key => $value) {
$array[$key] = json_decode($array[$key], TRUE);
}
echo $array['order_item'][0]['sku'];
这将给出: 14b6c7e2f838fd356
答案 1 :(得分:0)
在php中创建多维数组的正确方法如下:
$ array ['order_item'] ['name'] =“产品”;
等等