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

Solved Add/remove an element out of config's array?

Discussion in 'Development' started by WinterBuild7074, Jun 29, 2017.

  1. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    What is the shortest code to add/remove an element out of an config's array?
    Example:

    Code:
    worlds:
    - "World1"
    - "World2"
    - "World3"
    
    to

    Code:
    worlds:
    - "World1"
    - "World2"
    - "World3"
    - "World4"
    
    Maybe there's something like this?
    Code:
    $this->getConfig()->add("anything", $myarray");
    
     
  2. falk

    falk Slime Poggit Reviewer

    Messages:
    75
    GitHub:
    falkirks
    PHP:
    $arr $this->getConfig()->get("anything");
    $arr[] = "World4";
    $this->getConfig()->set("anything"$arr);
     
    corytortoise and Thunder33345 like this.
  3. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    to remove you will need to array search and unset then set the array onto the config
     
  4. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Note that it is faster to remove a key from an array than searching a value and remove its associated key.
     
    corytortoise likes 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.