I am trying to create a minigame, there I try to implement a function to let the player join a random game: PHP: public $games = ["Game1" => ["AbleToJoin", *player1*, *player2*...], "Game2" => ["InGame", *player1*, *player2*, *player3*...]];// *player* = players who are in this gamepublic function joinGame($player){foreach($this->games as $game){$level = $this->getServer()->getLevelByName($game);if(count($this->game[$game]) > 6 + 1){ // game not full$player->teleport(new Vector3($level->getSafeSpawn));$player->sendMessage("You joined $game");return;}} There are coming errors that I give an array instead of a string (as example on getLevelByName(), but as you can "Game1" is a string... I would appreciate your help.
what the ... you only foreached the array, so the foreached var will have arrays as well like you defined on the top, so it will return those array, not "Game1" "Game2" etc.
You're only getting the values(players) and not the key(game). PHP: foreach ($this->games as $game => $players){//todo//note $players give another array.}