0
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.

1
  • By the way: Welcome to Stack Overflow! Commented Oct 21, 2011 at 14:33

3 Answers 3

2

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
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks! Someone else beat you to the punch, but that answer is correct as well.
+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 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
1
$data = Minequery::query("64.31.24.137");
echo $data['serverPort'];
echo $data['playerList'][0];

Read up on PHP Arrays

1 Comment

You're a life saver! Alright, in 12 minutes (time restriction) I will make this the best answer.
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 )

4 Comments

You forgot the quotes for playerlist!
A bit round about and $playerList = $serverDetails[playerList]; will fail.
@ComFreek If you see silly mistakes, edit the question and correct them, you'll earn rep!
@fredley: Okay, next time I'll do it ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.