Blogger Information
Blog 10
fans 0
comment 0
visits 4942
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
10月11日作业
鬼才哥-秋兜
Original
345 people have browsed it

动态表格案例代码

  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>
Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post