数组索引的变量

时间:2017-07-21 10:30:18

标签: php

我唯一想到的就是尝试使这段代码有效:

$index = [$player]['matchHistory'][$matchIndex];
$players . $index . ['platformId'];

试图获得最终结果

$players[$playerIndex]['matchHistory'][$matchIndex]['platformId'];

但是使用此代码,我收到此错误

Fatal error: Assignments can only happen to writable values in C:\Users\elvarp\Documents\webdev\iceleague\testing.php on line 39

这可能在PHP中吗?没有足够的知识谷歌这个。

编辑:我正在使用的完整代码:

foreach ($players as $playerIndex => $player) {
  $matchHistory = $api->getRecentMatchList($player['summonerAccountId'], "season=9");
  foreach ($matchHistory['matches'] as $matchIndex => $match) {
    $index = [$playerIndex]['matchHistory'][$matchIndex];
    $players . $index . ['platformId'] = $match['platformId'];
    $players . $index . ['matchId'] = $match['gameId'];
    $players . $index . ['championId'] = $match['champion'];
    $players . $index . ['queue'] = $match['queue'];
    $players . $index . ['season'] = $match['season'];
    $players . $index . ['timestamp'] = $match['timestamp'];
    $players . $index . ['role'] = $match['role'];
    $players . $index . ['lane'] = $match['lane'];
  }
}

$ player

的价值
Array
(
    [summonerName] => Retro
    [summonerId] => 27467980
    [summonerAccountId] => 31905356
)

0 个答案:

没有答案