我想显示名称和类型,但不起作用。我该怎么办?
$ json:
{"222":{"id":"222","name":"Shirt1","type":"Men","product":"1","count":"2","price":7000},"223":{"id":"223","name":"Shirt2","type":"Men","product":"2","count":"1","price":4000},"224":{"id":"224","name":"Shirt3","product":"3","count":"2","price":14000}}
解码:
$products = json_decode($json, true);
foreach ($products['id'] as $k => $v)
{
var_dump(array_key_exists('name', $v));
}
答案 0 :(得分:1)
$products = json_decode($json, true);
$result = '';
foreach( $products as $product ) {
$result .= 'Name : ' . $product['name'] . ', type : ' . $product['type'] . ';';
}
echo $result;