Blogger Information
Blog 1
fans 0
comment 0
visits 346
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
自定义函数应用(动态表格样式)
Original
346 people have browsed it

```php

$headstr=[‘编号’,’姓名’,’年龄’,’地区’];
$strr=[
[‘id’=>1001,’name’=>’小梁’,’age’=>18,’area’=>’深圳’],[‘id’=>1002,’name’=>’小陈’,’age’=>22,’area’=>’珠海’],[‘id’=>1003,’name’=>’小明’,’age’=>25,’area’=>’东莞’],[‘id’=>1004,’name’=>’小新’,’age’=>20,’area’=>’惠州’]
];
function table_css($str,$headstr,$t_css){

  1. $table_css="<table class='$t_css'>";
  2. $table_css .="<thead>";
  3. $table_css .="<tr>";
  4. foreach($headstr as $h_value){
  5. $table_css .="<th>" .$h_value;
  6. $table_css .="</th>";
  7. }
  8. $table_css .="</tr>";
  9. $table_css .="</thead>";
  10. $table_css .="<tbody>";
  11. foreach($str as $key => $value){
  12. $table_css .="<tr>";
  13. foreach($value as $key2 => $value2){
  14. $table_css .="<td>" . $value2;
  15. $table_css .="</td>";
  16. }
  17. $table_css .="</tr>";
  18. }
  19. $table_css .="</tbody>";
  20. return $table_css;
  21. }
  22. echo table_css($strr,$headstr,'t_css');
  23. ?>
  24. <style>
  25. .t_css{
  26. width:calc(100vw - 40px);
  27. border: 1px solid #333;
  28. border-collapse:collapse;
  29. margin:0 auto;
  30. }
  31. .t_css td,.t_css th{
  32. border: 1px solid #333;
  33. text-align:center;
  34. empty-cells: show;
  35. padding:1rem;
  36. }
  37. .t_css thead{
  38. background-color: #e0e0e0;
  39. }
  40. .t_css tbody > tr:nth-of-type(odd){
  41. background-color: #f2f2f2;
  42. }
  43. /* tr:nth-type-of(2){
  44. background-color:#000;
  45. } */
  46. </style>

```

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