我有一个json解码数组,如$ json = json_decode($ curl_result);如何使用foreach循环获取此数组,我想尽可能减少数组循环。你能编写我能访问这些值的正确代码吗?
数组如下所示
Array
(
[SITEResponse] => Array
(
[@version] => 1.0
[SoftwareProducts] => Array
(
[@numFound] => 408
[@numReturned] => 10
[@start] => 0
[SoftwareProduct] => Array
(
[0] => Array
(
[Summary] => Array
(
[$] => summery of software.
)
[Requirements] => Array
(
)
[ContentIds] => Array
(
)
[CleverBridgeUrl] => Array
(
)
[BuyNowUrl] => Array
(
[$] => http://www.abc.com
[@type] => dl_buy_pub
)
[BetaRelease] => Array
(
[$] => false
)
[LinkURL] => Array
(
[$] => http://www.abc.com
)
)
)
)
)
)
现在我想得到这个数组的每个值,但是如何???请帮忙 感谢。
答案 0 :(得分:1)
$version = $json['SITEResponse']['@version'];
$numFound = $json['SITEResponse']['SoftwareProducts']['@numFound'];
...
...
foreach( $json['SITEResponse']['SoftwareProducts']['SoftwareProduct'] as $key=>$product ){
$Summary= $product['Summary']['$'];
$BuyNowUrl = $product['BuyNowUrl']['$'];
...
...
...
}