Skip to content

Instantly share code, notes, and snippets.

@PJZ9n
Last active June 13, 2020 06:55
Show Gist options
  • Save PJZ9n/22602e8763c6acdf502ab49593ce646a to your computer and use it in GitHub Desktop.
Save PJZ9n/22602e8763c6acdf502ab49593ce646a to your computer and use it in GitHub Desktop.
オンラインプレイヤーの名前を取得する
<?php
declare(strict_types=1);
use pocketmine\Server;
use pocketmine\Player;
//オンラインのプレイヤーを全員取得
//[object Player, object Player, object Player]
$onlinePlayers = Server::getInstance()->getOnlinePlayers();
//プレイヤー名の配列を作る
//[Steve, Alex, Hoge]
$onlinePlayerNames = array_map(function ($player) { return $player->getName(); }, $onlinePlayers);
//これと同じ
/*$onlinePlayerNames = [];
foreach ($onlinePlayers as $onlinePlayer) {
$onlinePlayerNames[] = $onlinePlayer->getName();
}*/
//プレイヤー名の配列から文字列を作る
$playerNameString = implode(", ", $onlinePlayerNames);
//表示する
var_dump($playerNameString);//string("Steve, Alex, Hoge")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment