PageRenderTime 37ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/grid.php

https://github.com/ptraverse/soapyclustal
PHP | 57 lines | 43 code | 10 blank | 4 comment | 0 complexity | 9e6e20528ba7f9a180dbe03304e288eb MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. $ed1 = array(
  3. "Name"=>"HelloWorld",
  4. "Language"=>"php",
  5. "Example"=>'<a href="./helloworld_client/client.php">Link</a>',
  6. "Spec"=>'<a href="./spec/helloworld.php">Link</a>');
  7. $ed2 = array(
  8. "Name"=>"NW",
  9. "Language"=>"php",
  10. "Example"=>'<a href="./nw_client/client.php">Link</a>',
  11. "Spec"=>'<a href="./spec/nw.php">Link</a>');
  12. $ed3 = array(
  13. "Name"=>"NW-Advanced",
  14. "Language"=>"php",
  15. "Example"=>'<a href="./nwa_client/client.php">Link</a>',
  16. "Spec"=>'<a href="./spec/nwa.php">Link</a>');
  17. $ed4 = array("Name"=>"Viterbi","Language"=>"c#","Example"=>"link","Spec"=>"link");
  18. $example_data = array($ed1, $ed2, $ed3,$ed4);
  19. echo '<div style="width: 400px; text-align: center; margin-left:auto; margin-right: auto;margin-top: 76px;">';
  20. echo array_to_html_grid($example_data);
  21. echo '</div>';
  22. /**
  23. * input_array: assoc 2d array
  24. * output: html grid
  25. **/
  26. function array_to_html_grid($input_array)
  27. {
  28. $counter = 0;
  29. $html = "<table border=1><tr>";
  30. foreach($input_array[0] as $k=>$v)
  31. {
  32. $html .= "<th>".$k."</th>";
  33. }
  34. $html .= "</tr>";
  35. foreach ($input_array as $k=>$v)
  36. {
  37. $html .= "<tr>";
  38. foreach ($v as $k2=>$v2)
  39. {
  40. $html .= "<td>".$v2."</td>";
  41. }
  42. $html .= "</tr>";
  43. }
  44. $html .= "</table>";
  45. return $html;
  46. }
  47. ?>