博客列表 >10月11日作业

10月11日作业

鬼才哥-秋兜
鬼才哥-秋兜原创
2021年10月12日 16:15:00338浏览

动态表格案例代码

  1. <?php
  2. $qd = [
  3. [
  4. 'a1'=>'内容1',
  5. 'a2'=>'内容1',
  6. 'a3'=>'内容1',
  7. 'a4'=>'内容1',
  8. 'a5'=>'内容1'
  9. ],
  10. [
  11. 'b1'=>'内容2',
  12. 'b2'=>'内容2',
  13. 'b3'=>'内容2',
  14. 'b4'=>'内容2',
  15. 'b5'=>'内容2'
  16. ]
  17. ];
  18. $head = [
  19. '头部内容1',
  20. '头部内容1',
  21. '头部内容1',
  22. '头部内容1',
  23. '头部内容1',
  24. ];
  25. function tab(array $qd,$head,int $width=300){
  26. $table = '<table border="2">';
  27. $table .= '<thead>';
  28. $table .= '<tr>';
  29. foreach($head as $head_k=>$head_v){
  30. $table .= '<th width="'. $width .'">'. $head_v .'</th>';
  31. }
  32. $table .= '</tr>';
  33. $table .= '</thead>';
  34. $table .= '<tbody>';
  35. foreach($qd as $k=>$v){
  36. $table .= '<tr>';
  37. foreach($v as $kk=>$vv){
  38. $table .= '<td>'. $vv .'</td>';
  39. }
  40. $table .= '</tr>';
  41. }
  42. $table .= '</tbody>';
  43. $table .= '</table>';
  44. return $table;
  45. }
  46. ?>
  47. <!DOCTYPE html>
  48. <html lang="en">
  49. <head>
  50. <meta charset="UTF-8">
  51. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  52. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  53. <title>Document</title>
  54. </head>
  55. <body>
  56. <?php echo tab($qd,$head); ?>
  57. </body>
  58. </html>
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议