Im trying to use API. I get data coded in JSON in array.
Now I need to encode the array to get the value I need, but don't know exactly how to do it. I want to get pln value.
This is what I get:
object(stdClass)#1 (2) {
["status"]=> string(2) "ok"
["data"]=> object(stdClass)#2 (4) {
["pln"]=> string(6) "0.0000"
["usd"]=> string(6) "0.0000"
["btc"]=> string(10) "0.00000000"
["eur"]=> string(6) "0.0000"
}
}
Orginal API code:
function getBalance($url){
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
$url = $main_api_url.'balance/'.$api_user_id.'/'.$api_key.'/'.$api_secret.'/';
var_dump(
json_decode(
getBalance($url)
)
);
This is my code:
function getBalance($url){
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
$url = $main_api_url.'balance/'.$api_user_id.'/'.$api_key.'/'.$api_secret.'/';
$json = file_get_contents($url);
$data = json_decode($json, TRUE);
print "$data[pln]";
How I can get exactly pln value? Im not interested in whole array.
<pre>before var_dump $data ? Not sure but i think u can access 'pln' like this$data->data->pln