I put one of player in config that is selected before by randomly. So now I want to put all of players to Config except one of player that is selected before randomly. How can I? Code: $all = $this->getServer()->getOnlinePlayers(); $o = $all[array_rand($all)]; $p = $this->List->getAll(); $p["RandomOfPlayer"][] = "{$o->getName()}"; $this->List->setAll($p); $this->List->save();
use array_splice to remove the random player from the array PHP: array_splice($all, array_search($o, $all)); Edit: fixed a mistake
ErrorException: "array_splice() expects parameter 2 to be int, string given" (EXCEPTION) error happened Code: $all = $this->getServer()->getOnlinePlayers(); $o = $all[array_rand($all)]; $this->P["Hum"] = array_splice($all, array_search($o, $all)); $Hum = $this->P["Hum"]; $Hum->getInventory()->addItem(Item::get(1, 0, 1)); }
ok apparently i'm an idot, i didn't realize array_rand returns an int, so u can do it like this: PHP: array_splice($all, $o); and like that it shouldn't give an error