我正在创建一个顶级站点,并且我有一个关于回显多维数组的某个元素的问题。我正在使用一个名为GameQ的库来 ping 游戏服务器以获取所述服务器的统计信息。我无法从我指定的数组中的某些元素打印结果。
我的代码:
<?php
// Include the main class file
require '../GameQ.php';
$gq = new GameQ();
$gq->addServer(array(
'id' => '0',
'type' => 'minecraft',
'host' => '192.210.238.76:25865',
));
$results = $gq->requestData(); // Returns an array of results
//Below line returns a error: Notice: Undefined offset: 0
echo "Online: " . $results[0]['numplayers'] . "/" . $results[0]['maxplayers'] . "<br />";
var_dump($results);
?>
数组 Var 转储:
array (size=1)
'192.210.238.76:25865' =>
array (size=17)
'hostname' => string 'A Whole Other Level' (length=19)
'gametype' => string 'SMP' (length=3)
'game_id' => string 'MINECRAFT' (length=9)
'version' => string '1.6.4' (length=5)
'plugins' => string 'CraftBukkit on Bukkit 1.6.4-R0.1-SNAPSHOT' (length=41)
'map' => string 'Build' (length=5)
'numplayers' => string '6' (length=1)
'maxplayers' => string '30' (length=2)
'hostport' => string '25865' (length=5)
'hostip' => string '192.210.238.76' (length=14)
'players' =>
array (size=6)
0 =>
array (size=1)
...
1 =>
array (size=1)
...
2 =>
array (size=1)
...
3 =>
array (size=1)
...
4 =>
array (size=1)
...
5 =>
array (size=1)
...
'gq_online' => boolean true
'gq_address' => string '192.210.238.76' (length=14)
'gq_port' => string '25865' (length=5)
'gq_protocol' => string 'gamespy3' (length=8)
'gq_type' => string 'minecraft' (length=9)
'gq_transport' => string 'udp' (length=3)
我已经在 Manual 中查看了数组的手册。我将不胜感激任何人对此主题的帮助。我知道我错过了一些东西。在注册提出这个问题之前,我试图先搜索答案。我认为搜索结果比等待某人帮助我答案要快。感谢您的患者和您的理解。快乐编码!