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

时间:2011-10-21 14:28:22

标签: php arrays class function loops

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,我想我只知道一点点。

3 个答案:

答案 0 :(得分:2)

使用此代码:

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

答案 1 :(得分:1)

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

阅读PHP Arrays

答案 2 :(得分:0)

$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 )