Hi So i have config: --- Members: - Vasya - Petya - Itakdalee ... How can i delete in this array, for example, "Petya"? Help me, please
PHP: $members = $this->getConfig()->get("Members", []);unset($members["Petya"]);$this->getConfig()->set("Members", $members);
Can you show me, how to remove CONSOLE from here (not from Creater) - sjs: Creater: CONSOLE Members: - CONSOLE - Pie
assuming sjs is on the same level as Creater and Members, this code can be used: PHP: $members = $this->getConfig()->get("Members", []);unset($members["CONSOLE"]);$this->getConfig()->set("Members", $members);
Wow, you just posted the exact same code I posted above, with the name changed to "CONSOLE", congrats
I hope someone this can help: Config: --- test: Members: - steve1 - CONSOLE - steve2 ... Code: $this->getConfig()->reload(); $r = "CONSOLE"; //need to remove $a1 = "test"; $array = $this->getConfig()->getAll()[$a1]["Members"]; //members array $new = []; foreach($array as $value){ if($value != $r){ $new[] = $value;}} $this->getConfig()->setNested($a1.".Members", $new); $this->getConfig()->save();
Code: --- test: Members: - steve1 - CONSOLE - steve2 ... PHP: $this->getConfig()->reload();$r = "CONSOLE"; //need to remove$a = "test";$members = $this->getConfig()->getAll()[$a]["Members"]; //members array$new = [];foreach($members as $member){ if($member !== $r){ $new[] = $member; }}$this->getConfig()->setNested($a.".Members", $new);$this->getConfig()->save();
PHP: public function onEnable() { if(!file_exists($this->getDataFolder())) { @mkdir($this->getDataFolder()); $this->saveResource("yourconfig.yml"); }else if(!file_exists($this->getDataFolder()."yourconfig.yml")) { $this->saveResource("yourconfig.yml"); } $this->cfg = new Config($this->getDataFolder()."configname.yml"); $this->getLogger()->info("Enabled !"); } //Function to set Members and save $name = $event->getPlayer()->getName(); $cfg = $this->cfg->get("Members"); $add['Player'] = $name; $i = 0; $while = true; while($while) { if(!isset($cfg[$i])) { $cfg[$i] = $add; $this->cfg->set("Members",$cfg); $this->cfg->save(); $while = false; }else { $i++; } } }