Last active
June 13, 2020 06:55
-
-
Save PJZ9n/22602e8763c6acdf502ab49593ce646a to your computer and use it in GitHub Desktop.
オンラインプレイヤーの名前を取得する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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