Blabla3 - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of Blabla3.php
- <?php
- $jsonData = '[{"teamId":0,"playerId":84632,"playerName":"Flo_McFly","distance":23.660475},{"teamId":2,"playerId":89711,"playerName":"Carlos_Trouble","distance":0.0},{"teamId":2,"playerId":55555,"playerName":"Max_Mustermann (UG)","distance":15.0},{"teamId":1,"playerId":12345,"playerName":"Siggi_Siggi","distance":133.7}]';
- $teams = array(0 => 'Zivilist', 1 => 'Yakuza', 2 => 'Ballas');
- $data = json_decode($jsonData);
- $sortedData = array();
- foreach ($data as $key => $item) {
- $sortedData[$item->teamId][] = $item;
- }
- ksort($sortedData, SORT_NUMERIC);
- $output = '<table border="1"><thead><tr><th>ID</th><th>Name</th><th>Entfernung</th></tr></thead><tbody>';
- foreach ($sortedData as $key => $value) {
- $output .= '<tr><th colspan="4">' . $teams[$key] . '</th></tr>';
- foreach ($value as $tkey => $tvalue) {
- $output .= '<tr><td>'.$tvalue->playerId.'</td><td>'.$tvalue->playerName.'</td><td>'.number_format($tvalue->distance, 2).'</td></tr>';
- }
- }
- $output .= '</tbody></table>';
- echo $output;