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.



Your result can be seen below.

Result of php executing





Full code of Blabla3.php

  1. <?php
  2. $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}]';
  3. $teams = array(0 => 'Zivilist', 1 => 'Yakuza', 2 => 'Ballas');
  4.  
  5. $data = json_decode($jsonData);
  6. $sortedData = array();
  7.  
  8. foreach ($data as $key => $item) {
  9.    $sortedData[$item->teamId][] = $item;
  10. }
  11.  
  12. ksort($sortedData, SORT_NUMERIC);
  13.  
  14. $output = '<table border="1"><thead><tr><th>ID</th><th>Name</th><th>Entfernung</th></tr></thead><tbody>';
  15. foreach ($sortedData as $key => $value) {
  16.     $output .= '<tr><th colspan="4">' . $teams[$key] . '</th></tr>';
  17.     foreach ($value as $tkey => $tvalue) {
  18.         $output .= '<tr><td>'.$tvalue->playerId.'</td><td>'.$tvalue->playerName.'</td><td>'.number_format($tvalue->distance, 2).'</td></tr>';   
  19.     }
  20. }
  21. $output .= '</tbody></table>';
  22.  
  23. echo $output;
File Description
  • Blabla3
  • PHP Code
  • 21 Aug-2023
  • 1021 Bytes
You can Share it: