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

Add Multiple Values to a Key (YAML Config)

Discussion in 'Development' started by ShushImSam, Aug 12, 2019.

  1. ShushImSam

    ShushImSam Spider Jockey

    Messages:
    37
    Alright so basically what I want to do, is everytime someone gets muted(ive done that) I want the reason to be stored in a YAML under his name which is fine for the first one, although the second time he gets muted I want it to be stored as as second value, not overiding the second one
    Ex:
    Code:
    Steve:
    - Advertising
    - Hacking
    And then I want to be able to get these values as a string but every value has a new line
    Ex:
    Code:
    $reasons = '';
    foreach ($this->mute->getNested("$name.Mute") as $reason) {
             $reasons .= '\n-' . $reason;
       }
    How would I do that? Ive tried many things but can't get to make it work
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    You don't have to manually encode or decode YAML yourself. "Steve" is an array containing the elements listed below it. You just yaml_emit(["Steve" => ["Advertising", "Hacking"]]) to get that result you showed in your yml file, and yaml_parse($file_contents) to get the array back.
     
    HimbeersaftLP, ShushImSam and GamakCZ like this.
  3. ShushImSam

    ShushImSam Spider Jockey

    Messages:
    37
    Though they'll be more than one person in one file
     
  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.