teams = []; foreach ($rawData as $key => $team) { $players = []; if (is_array($team['players'])) { foreach ($team['players'] as $player) { if (!empty($player['inGameName'])) { $players[] = $player['inGameName']; } } } $this->teams[] = [ 'name' => $team['name'], 'players' => $players ]; } return (bool)count($this->teams); } public function getTeamNames() { return array_column($this->teams, 'name'); } /** * @return string[] */ public function getTeams(): array { return $this->teams; } /** * @param string[] $teams * @return TeamList */ public function setTeams(array $teams): TeamList { $this->teams = $teams; return $this; } public function getJson() { return json_encode($this->teams); } }