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

Solved Unset a key from yaml

Discussion in 'Development' started by minijaham, Jul 31, 2021.

  1. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    I've been trying to remove a key from my config!
    Example:

    I want to remove "Mojang" from this config:
    PHP:
    Microsoft:
        
    Mojang:
            
    Bugs1230
            Employees
    69
        Minecraft
    :
            
    Bugs200000
            Ceo
    minijaham
    My previous attempt:
    PHP:
    foreach ($data->get("Microsoft") as $val => $key) {
        
    $name array_search($val$data->get("Microsoft"));
        
    var_dump($name); // Outputs Mojang and Minecraft (string)
        
    unset($data->get("Microsoft")[$name]); // bool(false) ???? wtf
    }
    $data->save();
    I know I'm doing something incorrectly, as I've done this before.
    But I can't quite figure out what I am doing wrong!
     
    Last edited: Aug 1, 2021
  2. HeyDeniis_

    HeyDeniis_ Baby Zombie

    Messages:
    137
    try
    PHP:
    $all $data->get("Microsoft");
    unset(
    $all["Mojang"]);
    $data->set("Microsoft"$all);
    $data->save();
     
    minijaham likes this.
  3. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    Now that I think about it, I think I forgot to set the unsetted values.
    I feel so dumb! I'll try it and come back with a result :D Thank you!
     
    Agent likes this.
  4. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    Agent 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.