Reputation: 6488
I printed out what was supposed to be a multidimensional array in php but saw this instead. It was throwing errors when I tried to access $array['order_item']['sku']
. How do I convert this to a proper multidimensional 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":"[email protected]"}
)
Upvotes: 0
Views: 55
Reputation: 686
try this one
$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":"[email protected]"}'
);
foreach ($array as $key => $value) {
$array[$key] = json_decode($array[$key], TRUE);
}
echo $array['order_item'][0]['sku'];
this will give: 14b6c7e2f838fd356
Upvotes: 1
Reputation: 73
The proper way to create multidimensional arrays in php is as follows:
$array['order_item']['name'] = "Product";
And so on
Upvotes: 0