一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - PHP教程 - 將php數組輸出html表格的方法

將php數組輸出html表格的方法

2020-06-12 16:12PHP開發網 PHP教程

這篇文章主要介紹了將php數組輸出html表格的方法,需要的朋友可以參考下

復制代碼 代碼如下:


<?html">php
class xtable
{
 private $tit,$arr,$fons,$sextra;
 public function __construct()
 {
  $this->tit=array();       // strings with titles for first row
  $this->arr=array();       // data to show on cells
  $this->fons=array("#EEEEEE","#CCEEEE");  // background colors for odd and even rows
  $this->sextra="";       // extra html code for table tag
 }

 public function extra($s)      // add some html code for the tag table
 {
  $this->sextra=$s;
 }
 public function background($arr) {if (is_array($arr)) $this->fons=$arr; else $this->fons=array($arr,$arr);}
 public function titles($text,$style="") {$this->tit=$text; $this->sesttit=$style;}
 public function addrow($a) {$this->arr[]=$a;}
 public function addrows($arr) {$n=count($arr); for($i=0;$i<$n;$i++) $this->addrow($arr[$i]);}
 public function html()
 {
  $cfondos=$this->fons;
  $titulos="<tr>";
  $t=count($this->tit);
  for($k=0;$k<$t;$k++)
  {
   $titulos.=sprintf("<th>%s</th>",$this->tit[$k]);
  }
  $titulos.="</tr>";

  $celdas="";
  $n=count($this->arr);
  for($i=0;$i<$n;$i++)
  {
   $celdas.=sprintf("<tr style='background-color:%s'>",$this->fons[$i%2]);
   $linea=$this->arr[$i];
   $m=count($linea);
   for($j=0;$j<$m;$j++)
    $celdas.=sprintf("<td  %s>%s</td>","",$linea[$j]);
   $celdas.="</tr>";
  }
  return sprintf("<table cellpadding='0' cellspacing='0' border='1' %s>%s%s</table>",$this->sextra,$titulos,$celdas);
 }
 public function example()
 {
  $tit=array("Apellidos","Nombre","Telefono");
  $r1=array("Garcia","Ivan","888");
  $r2=array("Marco","Alfonso","555");
  $x=new xtable();
  $x->titles($tit);      //take titles array
  $x->addrows(array($r1,$r2));   // take all rows at same time
  return $x->html();     //return html code to get/show/save it
 }
}

 


// Example
$t1=new xtable();
echo $t1->example()."<hr />";

$t2=new xtable();
for($i=1;$i<=10;$i+=2)
 {
  $t2->addrow(array("ODD",$i));
  $t2->addrow(array("EVEN",$i+1));
 }
$t2->background(array("pink","gold"));
$t2->titles(array("TYPE","#"));
$t2->extra(" style='width:500px; background-color:cyan; color:navy;'");
echo $t2->html()."<hr />";

$t3=new xtable();
for($i=1;$i<=6;$i++)
 {
  $t3->addrow(array("5x".$i,5*$i));

 }
$t3->background(array("olive","maroon"));
$t3->titles(array("Multiplication table","5"));
$t3->extra("style='border:dotted red 10px; padding-left:4px;padding-right:4px; text-align:right;width:500px; background-color:black; color:white;'");
echo $t3->html()."<hr />";

$t4=new xtable();
$a=array("#");
for($i=1;$i<=10;$i++)
 {
  $a[]=$i;
 }
$t4->addrow($a);
$t4->background(array("pink","gold"));
$tit=array(); $tit[]="Numbers";
for($i=1;$i<=10;$i++) $tit[]="#";
$t4->titles($tit);
$t4->extra("style='border:solid 1px silver; padding-left:4px;padding-right:4px; text-align:center;width:500px; background-color:cyan; color:navy;'");
echo $t4->html()."<hr />";
?>

 

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 日韩欧美亚洲每日更新网 | 青青青国产手机在线播放 | 欧美人妖草草xxoo | 日韩三及片 | 娇喘高潮教室h | 欧美亚洲高清日韩成人 | ai换脸明星造梦工厂忘忧草 | 超级乱淫变态伦短篇小说全集 | 99久久香蕉国产综合影院 | 四虎网站网址 | 久久视频这有精品63在线国产 | 色婷婷狠狠 | 精品国产欧美一区二区三区成人 | 男人的j放进女人的p全黄 | 小寡妇好紧进去了好大看视频 | 成人免费视频大全 | 免费特黄一级欧美大片在线看 | 亚洲va久久久噜噜噜久久狠狠 | 亚洲精品私拍国产福利在线 | 92国产福利视频一区二区 | 午夜宅男宅女看在线观看 | 丝瓜茄子绿巨人秋葵榴莲污 | 调教小龙女 | 性xxxxⅹhd成人| 久久夜色噜噜噜亚洲AV0000 | 99爱在线精品视频免费观看9 | 99精品网 | 任你操视频在线观看 | 国产白虎 | 村上里沙40分钟在线观看 | 明星h文集合短篇小说 | 亚洲激情在线视频 | 精品一久久香蕉国产二月 | 无码人妻精品一区二区蜜桃在线看 | 好爽好紧小雪别夹小说 | 色老板在线| 5g影院天天爽 | 亚洲一区二区日韩欧美gif | 30分钟的高清视频在线观看 | 91丝袜足控免费网站xx | 精品日本一区二区 |