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

How can I get All Players and put as array?

Discussion in 'Development' started by Hoyee, Jun 15, 2020.

  1. Hoyee

    Hoyee Baby Zombie

    Messages:
    126
    Code:
    $all = $this->getServer()->getOnlinePlayers();
    put that in $this->ex["Players"][] as array.

    $this->ex["Players"][] = $all;

    this doesn't work.

    how can I?
     
  2. Slayer1K

    Slayer1K Spider

    Messages:
    11
    GitHub:
    slayer1k
    Maybe you should use foreach.
    Code:
    foreach($this->getServer()->getOnlinePlayers() as $player){
      $this->ex['Players'] = $player->getName();
    }
    I don't know if it works.
     
  3. Mohagames205

    Mohagames205 Spider Jockey

    Messages:
    26
    GitHub:
    mohagames205
    That won't work, now you're setting a new name to the same key everytime. To achieve what you want you would need to use this

    Code:
    foreach($this->getServer()->getOnlinePlayers() as $player){
      $this->ex['Players'][] = $player->getName();
    }
    This will make an associative array like this:

    Code:
    <?php
    
    $arr = ["Players" => ["player1", "player2", "player3"]];
    
    ?>
     
  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.