Guest User

Untitled

a guest
Nov 22nd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. <?php
  2. $data=array(
  3. array("Volvo",22,18),
  4. array("BMW",15,13),
  5. array("Saab",5,2),
  6. array("Land Rover",17,15)
  7. );
  8. function parseCol($col){
  9. return "<td>$col</td>";
  10. }
  11. function parseRow($row){
  12. $row=join("",array_map("parsecol",$row));
  13. return "<tr>$row</tr>";
  14. }
  15. $table=join("",array_map("parseRow",$data));
  16. ?>
  17. <body>
  18. <table border="2" width='200'>
  19.  
  20. <tr>
  21. <th>Name</th>
  22. <th>Stock</th>
  23. <th>Sold</th>
  24. </tr>
  25. <?php
  26. for ($a=0; $a<count($data); $a++) {
  27. echo "<tr>";
  28. for ($b=0; $b<count($data[$a]); $b++) {
  29. echo "<td>".$data[$a][$b]."</td>";
  30. }
  31. echo "</tr>";
  32. }
  33. ?>
  34.  
  35. </table>
  36. <table border="2" width='200'>
  37. <tr>
  38. <th>Name</th>
  39. <th>Stock</th>
  40. <th>Sold</th>
  41. </tr>
  42. <?php
  43. foreach($data as $row){
  44. echo "<tr>";
  45. foreach($row as $col){
  46. echo "<td>$col</td>";
  47. }
  48. echo "<tr>";
  49. }
  50. ?>
  51. </table>
  52. <table border="2" width='200'>
  53. <tr>
  54. <th>Name</th>
  55. <th>Stock</th>
  56. <th>Sold</th>
  57. </tr>
  58. <?php echo $table; ?>
  59. </table>
  60. </body>
Add Comment
Please, Sign In to add comment