我有以下json
{
"status": "ok",
"totalResults": 2,
"articles": [
{
"source": {
"id": "cooking-recepie",
"name": "cooking recepie"
},
"author": "cooking recepie Staff",
"title": "lamb steak",
"description": "fffffffffffffffffffffff.”",
"url": "http://www.cooking-recepie.net/node/116605",
"urlToImage": "https://www.cooking-
recepie.net/sites/default/[type]/[nid]/conte-1801-cap-epa.jpg",
"publishedAt": "2018-02-02T01:00:00Z"
},
{
"source": {
"id": "cooking-recepie",
"name": "cooking recepie"
},
"author": "cooking recepie Staff",
"title": "Igghhhhhhhhhhhhhhhhhhhh?",
"description": "yhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.",
"url": "http://www.cooking-recepie.net/116598/inter-push-lautaro-
martinez",
"urlToImage": "https://www.cooking-recepie.net/sites/[nid]/Martinez-
Lautaro-Arg-epa_0_0.jpg",
"publishedAt": "2018-02-02T01:00:00Z"
}
]
}
-----------------------------到目前为止,我要测试的代码-------
<?php
$request = wp_remote_get( \'https://url\' );
if( is_wp_error( $request ) ) {
return false;
}
$body = wp_remote_retrieve_body( $request );
$data = json_decode( $body );
if( ! empty( $data ) ) {
if (is_array($data) || is_object($data))
{
foreach ($data as $key => $val){
echo \'data:\'.$data->$key->$val.\'<br>\';
echo \'key:\'.$key.\'<br>\';
echo \'val:\'. $val.\'<br>\';
}
}
}
?>
---------------------------响应-----------
data:
key:status
val:ok
data:
key:totalResults
val:2
data:
key:articles
val:Array
------------------------------我的问题----------------------
是对象还是数组?,我在一个php小部件中显示,但它不断出错
我需要显示所有信息,使用wp remote get-in php小部件实时显示是否安全如何缓存结果