0

I have this array:

array(4) { [0]=> array(4) { ["PlayerID"]=> int(0) ["Nickname"]=> string(15) "Peter" ["Score"]=> int(280) ["Ping"]=> int(322) } [1]=> array(4) { ["PlayerID"]=> int(1) ["Nickname"]=> string(4) "John" ["Score"]=> int(13265) ["Ping"]=> int(322) } [2]=> array(4) { ["PlayerID"]=> int(2) ["Nickname"]=> string(5) "Taylor" ["Score"]=> int(364) ["Ping"]=> int(281) } [3]=> array(4) { ["PlayerID"]=> int(7) ["Nickname"]=> string(7) "Mike" ["Score"]=> int(4656) ["Ping"]=> int(321) } }  

and I used this foreach loop:

$API = array(); 
foreach($API_GET as $ID => $Info)
 {
    $Player[$ID] = $Info;
    foreach($Info as $key => $value)
   { 
        $API[$key] = $value; 

    }
  }

and used this to echo Peter's nickname but it doesn't seem to work:

echo $Player['0']->$API[Nickname];
Stan69
  • 3
  • 3

1 Answers1

5

If you do

var_dump($Player['0']);

You will get

array(4) {
  ["PlayerID"]=>
  int(0)
  ["Nickname"]=>
  string(5) "Peter"
  ["Score"]=>
  int(280)
  ["Ping"]=>
  int(322)
}

So to echo Peter's Nickname you will have to do

echo $Player['0']['Nickname'];
Solaman Raji
  • 170
  • 9