Temuulen Optimistic Temuulen Optimistic - 6 months ago 12
PHP Question

PHP Get values from JSON

i have a question about json and php. I want to get the value in wins_ratio. How do i get that?



<?php
$jsondata = file_get_contents('https://api.worldoftanks.eu/wot/account/info/?application_id=ea6d19fe37d4b6b660f18c322a6ec219&account_id=' .$acc_account_id );
$info = json_decode($jsondata, TRUE);
$account = $info['data']['wins_ratio'][0];
foreach ($account as $acc) {
$acc_value = $acc['value'];
echo $acc_value;
}
?>





JSON File

enter image description here

PHP file

enter image description here

Answer

Use this code: Replace $info['data']['wins_ratio'][0] with $info['data']['521997295']['wins_ratio'] and $acc['value'] with only $acc in foreach loop

<?php 
$jsondata = file_get_contents('https://api.worldoftanks.eu/wot/account/info/?application_id=demo&account_id=' .$acc_account_id );
$info = json_decode($jsondata, TRUE);
$account = $info['data']['521997295']['wins_ratio'];
foreach ($account as $acc)
{
    echo $acc;
    echo "<br>";    
}
?>

To display rank value use, then there is no need of foreach loop

echo $info['data']['521997295']['wins_ratio']['value']; ///51.67

This will give you :

4690
278273
51.67

LIVE EXAMPLE CLICK HERE