0

The only thing i thought of was this trying to make this code work:

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

Trying to get this final outcome

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

But with this code, i get this error

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

Is this possible in php? Don't have enough knowledge to google this around.

EDIT: Full code i'm working with:

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'];
  }
}

The value of $player

Array
(
    [summonerName] => Retro
    [summonerId] => 27467980
    [summonerAccountId] => 31905356
)
  • Which line is your error ? This : `$players . $index . ['platformId'];` ? – Vincent Decaux Jul 21 '17 at 10:32
  • can you show values of `$player,$matchIndex,$playerIndex`? – Alive to die - Anant Jul 21 '17 at 10:33
  • Sorry forgot to put in the line which gives me the error. This is it. `$players . $index . ['platformId'] = $match['platformId'];` – Elvar Flatbaka Jul 21 '17 at 10:35
  • I edited the post to show the full code i'm working with. – Elvar Flatbaka Jul 21 '17 at 10:39
  • Uhm… how about just `$players[$playerIndex]['matchHistory'][$matchIndex] = $match;`…? There appears to be little point in you assigning each key in `$match` to `$players` manually. If you simply assign the whole array at once, your problem disappears entirely. – deceze Jul 21 '17 at 12:52
  • Otherwise you'd simply work with a reference: `$playerMatch = &$players[$playerIndex]['matchHistory'][$matchIndex]; $playerMatch['platformId'] = ...;` – deceze Jul 21 '17 at 12:53
  • I thought i had to assign each key in $match to $players, Thanks for showing me i could save the whole $match to $players, It's much better for this project. – Elvar Flatbaka Jul 21 '17 at 12:59

0 Answers0