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

Solved How do i get array key from a value?

Discussion in 'Plugin Help' started by Enrico Angelon, Nov 18, 2018.

  1. Enrico Angelon

    Enrico Angelon Spider Jockey

    Messages:
    37
    GitHub:
    herryyt
    i have a config db like this:
    Code:
    d4f6d43b-4989-3ab0-9d03-80694e247ebb:
      game_level: 22
      xp: 23565
      xp_left: 23629
      karma: 17144
      coins: 1915.000000
      xp_left_show: 64
      broken_blocks: 0
      language: english
      name: HerryYT
    d4f6d43b-4989-3ab0-9d03-20694e2443bb:
      game_level: 22
      xp: 23565
      xp_left: 23629
      karma: 17144
      coins: 1915.000000
      xp_left_show: 64
      broken_blocks: 0
      language: english
      name: OtherUser
    
    the first value is player uuid, how can i get the array by the name?
    like i wanna add coins to this player, i  have only his name, how do i get coins from his name?
     
    Last edited by a moderator: Dec 10, 2018
  2. Enrico Angelon

    Enrico Angelon Spider Jockey

    Messages:
    37
    GitHub:
    herryyt
    Oh i figured out myself...
    Code:
            foreach($this->data->getAll() as $key => $data)
            {
    
                if ($data["name"] == $player->getName()){
                    echo $data["coins"];
                    var_dump($data);
                }
                /*if ( $data[$field] === $value )
                    return $key;*/
            }
     
    ShushImSam 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.