当我执行下面的代码来访问koinex ticker api时,我得到一个数组,但是我怎么能只显示某些值:
echo $response[0][0][1];
echo $response['prices']['BTC'][0];
代码:
<?php
$getCurrency = "inr";
$displayArrayOutput = true;
// Get cURL resource
$curl = curl_init();
// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://koinex.in/api/ticker',
CURLOPT_USERAGENT => 'Something here'
));
// Send the request & save response to $resp
$response = curl_exec($curl);
// Close request to clear up some resources
$err = curl_error($curl);
curl_close($curl);
if ($err) {
} else {
if($displayArrayOutput){
$response = json_decode($response, true);
print_r($response);
}
else{
header("Content-type:application/json");
echo 'touine';
}
}
echo $response[0][0][1];
echo $response['prices']['BTC'][0];
?>
抱歉,对php有点新鲜,对任何其他解码json的方法开放