4

So I have been having some trouble printing my multi dimensional array into a table. Right now I

    Array
(
    [0] => stdClass Object
        (
            [id] => 00fa4033-421f-48d9-bc69-a0d9c9c4973e
            [name] => Chaka
        )

)

How can I output this data to an array. The code I am using to print the array is the following

$response = $status->getStatus('104.243.39.107');

if (!$response) {
    echo '<h2>STATUS: <span class="label label-danger">Offline</span></h2>';
} else {
    echo '<h2>STATUS: <span class="label label-success">Online</span></h2>';
    echo "Online Players " .$response['players']."/".$response['maxplayers'];
    echo '<br /><pre>';
    print_r($response['sample']); //THIS LINE
    echo '</pre>';
}

I have tried many methods to fix this but I am new to php.

Thanks for the help.

1 Answer 1

2

Try :

echo '<table><tr><th>Id</th><th>Name</th></tr>';
foreach ($response['sample'] as $player) {
    echo '<tr><td>'.$player->id.'</td><td>'.$player->name.'</td></tr>';
}
echo '</table>';
Sign up to request clarification or add additional context in comments.

Comments

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.