0

I am using an API which has a lot of data inside lots of arrays which as you may know can be quite confusing.I am relatively new to API's and this one in particular has no documentation.

My code below is grabbing the recent_games() function which is pulling the whole API then I am using foreach loops to get inside the data.

$games = $player->recent_games();

foreach($games['gameStatistics']['array'] as $key => $gameStatistic) {
    $game_date[strtotime($gameStatistic['createDate'])] = $gameStatistic;
}
// order data
krsort($game_date);

foreach ($game_date as $game => $data) {
    $statistics[$data] = $data['statistics'];
}

I am getting errors such as illegal offset for:

$statistics[$data] = $data['statistics'];

Is there a way to continue down the nesting of arrays ($game_date) to get to the data that I need?

Let me know if you need more info.

Thanks

EDIT more info:

The first foreach loop at the top loops a unix timestamp key per game. Looks like this:

[1370947566] => Array
    (
        [skinName] => Skin_name
        [ranked] => 1
        [statistics] => Array
            (
                 [array] => Array
                     (
                          [0] => Array
                              (
                                   [statType] => stat_data
                                   [value] => 1234
                              )
                          [1] => Array
                              (
                                   [statType] => stat_data
                                   [value] => 1234
                              )

As you can see its quite nested but I am trying to get to the individual statistics array. I hope that helps?

4

1 回答 1

3
$statistics[$data] = $data['statistics'];

这条线绝对不可能是正确的。

右手边$data就像一个数组一样使用,索引到它。左侧$data用作数组的键。由于键的唯一有效类型是字符串和整数,$data因此不能同时满足两个表达式的要求——它不能是数组字符串或整数。

从错误消息中可以明显看出$data它实际上是一个数组,因此将其按原样使用$staticstics[$data]是错误的。你想$statistics成为什么?

于 2013-06-11T19:40:18.593 回答