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

How to unset array key

Discussion in 'Development' started by Junkdude, May 2, 2019.

  1. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    I have been trying to remove an item from an array, but it wont work at all, it just does nothing.
    PHP:
    foreach($this->ah->getAll() as $key){
            
    //if($key == $aucid){
        
                
    $money EconomyAPI::getInstance()->myMoney($player);
                
    $sellname $key["seller"];
                
    $seller $this->getPlugin()->getServer()->getPlayer($sellname);
                
    $price $key["price"];
                
    $lore2 $key["lore"];
                
    $nbtencoded $key["item"]["nbt_b64"];
                
    $newnbt base64_decode($nbtencoded);
                
                
    $itemclicked->removeNamedTagEntry("auction id");
                
    $itemclicked->setLore($lore2);
                
    $money2 EconomyAPI::getInstance()->myMoney($seller);
                if(
    $money $price){
                    
    $player->sendMessage($this->getPlugin()->getError("Uh oh, you need more money to purchase this item"));
                    return 
    false;
                }

                if(
    $seller == $player){
                    
    $player->sendMessage($this->getPlugin()->getSuccess("Item removed"));
                    
    $player->getInventory()->addItem($itemclicked);
                    unset(
    $this->ah->getAll()[$aucid]);
                    
    $this->ah->save();
                    
    $this->menu->getInventory()->close($player);
                    return 
    true;
     
  2. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    1. $aucid is not defined
    2. To remove a key use $config->remove($key)
     
  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.