PHP - 从函数读取返回的数组

发布于 2024-12-11 08:38:50 字数 500 浏览 0 评论 0原文

require('mq_class.php');
print_r(Minequery::query("64.31.24.137"));

返回:

Array ( [serverPort] => 25565 [playerCount] => 6 [maxPlayers] => 40 [playerList] => Array ( [0] => Uthly [1] => epson8 [2] => CheeseBricks [3] => Truth92 [4] => zerokhaos [5] => plainlazy95 ) [latency] => 25.8100032806 )

现在,我将如何读取,例如 serverPort (变量)或 playerList (这是一个数组)?

我学PHP有一段时间了,我想我只知道一点点。

require('mq_class.php');
print_r(Minequery::query("64.31.24.137"));

returns:

Array ( [serverPort] => 25565 [playerCount] => 6 [maxPlayers] => 40 [playerList] => Array ( [0] => Uthly [1] => epson8 [2] => CheeseBricks [3] => Truth92 [4] => zerokhaos [5] => plainlazy95 ) [latency] => 25.8100032806 )

Now, how would I read, say serverPort (a variable) or playerList (which is an array)?

I've done PHP for a while now, I guess I know only a little amount.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

烟沫凡尘 2024-12-18 08:38:51

使用此代码:

$array = Minequery::query("64.31.24.137");
echo $array['serverPort']; // will print 25565
print_r($array['playerList']); // will print the subarray info

Use this code:

$array = Minequery::query("64.31.24.137");
echo $array['serverPort']; // will print 25565
print_r($array['playerList']); // will print the subarray info
温柔戏命师 2024-12-18 08:38:51
$data = Minequery::query("64.31.24.137");
echo $data['serverPort'];
echo $data['playerList'][0];

阅读 PHP 数组

$data = Minequery::query("64.31.24.137");
echo $data['serverPort'];
echo $data['playerList'][0];

Read up on PHP Arrays

梦里人 2024-12-18 08:38:51
$serverDetails = Minequery::query("54.31.24.137");
$serverPort = $serverDetails['serverPort'];
echo $serverPort; //25565
$playerList = $serverDetails['playerList'];
print_r($playerList); //Array ( [0] => Uthly [1] => epson8 [2] => CheeseBricks [3] => Truth92 [4] => zerokhaos [5] => plainlazy95 )
$serverDetails = Minequery::query("54.31.24.137");
$serverPort = $serverDetails['serverPort'];
echo $serverPort; //25565
$playerList = $serverDetails['playerList'];
print_r($playerList); //Array ( [0] => Uthly [1] => epson8 [2] => CheeseBricks [3] => Truth92 [4] => zerokhaos [5] => plainlazy95 )
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文