Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
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.

share|improve this question
    
By the way: Welcome to Stack Overflow! –  ComFreek Oct 21 '11 at 14:33

3 Answers 3

up vote 1 down vote accepted
$data = Minequery::query("64.31.24.137");
echo $data['serverPort'];
echo $data['playerList'][0];

Read up on PHP Arrays

share|improve this answer
    
You're a life saver! Alright, in 12 minutes (time restriction) I will make this the best answer. –  user1007301 Oct 21 '11 at 14:31
    
No worries. I encourage you to read the docs :) –  Jason McCreary Oct 21 '11 at 14:33

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
share|improve this answer
    
Thanks! Someone else beat you to the punch, but that answer is correct as well. –  user1007301 Oct 21 '11 at 14:32
    
+1 The answer I was putting together was identical to yours except without comment. LOL, these questions are a race. 3 answers, all of which are almost identical all arriving in less than a minute of each other. My answer would have been in here too but I saw the notice come up right before clicking submit. –  ghbarratt Oct 21 '11 at 14:35
    
@ghbarratt lol, you're right dude. Very few seconds and all right answer. I think this is an amazing community. Will we race again next time? :p –  Aurelio De Rosa Oct 21 '11 at 14:47
$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 )
share|improve this answer
    
You forgot the quotes for playerlist! –  ComFreek Oct 21 '11 at 14:31
    
A bit round about and $playerList = $serverDetails[playerList]; will fail. –  Jason McCreary Oct 21 '11 at 14:32
    
@ComFreek If you see silly mistakes, edit the question and correct them, you'll earn rep! –  Tom Medley Oct 21 '11 at 14:35
    
@fredley: Okay, next time I'll do it ;) –  ComFreek Oct 21 '11 at 16:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.