Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php wp_remote_get:获取接收到的数据_Php_Wordpress_Api - Fatal编程技术网

Php wp_remote_get:获取接收到的数据

Php wp_remote_get:获取接收到的数据,php,wordpress,api,Php,Wordpress,Api,我正在尝试使用此api获取特定数据(用于Wordpress博客): 我对数组感到迷茫,无法隔离特定数据:例如,如果我想要“chess_daily”的“Last”“rating”。下面是我使用的代码,但我不知道如何定位数据 <?php $request = wp_remote_get( 'https://api.chess.com/pub/player/erik/stats' ); if( is_wp_error( $request ) ) { return false; } $body

我正在尝试使用此api获取特定数据(用于Wordpress博客):

我对数组感到迷茫,无法隔离特定数据:例如,如果我想要“chess_daily”的“Last”“rating”。下面是我使用的代码,但我不知道如何定位数据

<?php $request = wp_remote_get( 'https://api.chess.com/pub/player/erik/stats' );
if( is_wp_error( $request ) ) {
return false; 
}
$body = wp_remote_retrieve_body( $request);
$test = json_decode( $body,true );
print_r ($test);
?>

PHP7添加了空合并运算符,这是从数组中获取数据的一种好方法。对于您的示例,您可以运行:

$last\u chess\u daily=$test['chess\u daily']['last']??无效的
返回:

数组(
“评级”=>1604,
“日期”=>1616714557,
“rd”=>51,
)