1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Remove a word from config

Discussion in 'Development' started by Kabluinc, Feb 11, 2017.

  1. Kabluinc

    Kabluinc Baby Zombie

    Messages:
    129
    HI,

    So I can set the players name to "test" to a config by doing
    Code:
    $this->getConfig()->setNested("test", $player->getName());
    But how can I remove "test" from config?

    Iv tried
    Code:
    unset($this->getConfig()->getAll()["test"]);
    But nothing happens.

    Please help.
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    PHP:
    $this->getConfig()->remove("test");
    OR, if you'd like to make use of unset, you can
    PHP:
    $cfg $this->getConfig()->getAll();
    unset(
    $cfg["test"]);
    $this->getConfig()->setAll($cfg);
    Source: Config.php
     
    Skullex and Awzaw like this.
  3. Bluplayz

    Bluplayz Spider Jockey

    Messages:
    43
    GitHub:
    bluplayz
    second one is useless ^^ the remove function was made to prevent the unset method ^^
     
  4. Jack Noordhuis

    Jack Noordhuis Zombie Pigman Poggit Reviewer

    Messages:
    618
    GitHub:
    JackNoordhuis
    The second one is not useless. The code takes the entire config as an array, unsets the specified key then sets the entire config data with the updated array. Please think before posting, in the future people will come searching for answers and if they see incorrect information they'll be mislead.
     
    Skullex, Muqsit and Bluplayz like this.
  5. Bluplayz

    Bluplayz Spider Jockey

    Messages:
    43
    GitHub:
    bluplayz
    i doesnt said that the second one doesnt work, i only say that they should use the Config::remove(); method ^^
     
  6. Jack Noordhuis

    Jack Noordhuis Zombie Pigman Poggit Reviewer

    Messages:
    618
    GitHub:
    JackNoordhuis
    When did I say that you said 'the second one' doesn't work? I was correcting your incorrect assumption of @Muqsit's second example method being useless.

    Can we not argue about who said what? There's no point taking the thread off topic just because of incorrect assumptions and personal opinions.
     
    Skullex, Sandertv and Muqsit like this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.