日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

PHP数组加表格_php数组输出html表格的操作方法

發布時間:2023/12/4 php 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 PHP数组加表格_php数组输出html表格的操作方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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;$iaddrow($arr[$i]);}

?public function html()

?{

??$cfondos=$this->fons;

??$titulos="

";

??$t=count($this->tit);

??for($k=0;$k

??{

???$titulos.=sprintf("

%s",$this->tit[$k]);

??}

??$titulos.="

";

??$celdas="";

??$n=count($this->arr);

??for($i=0;$i

??{

???$celdas.=sprintf("

",$this->fons[$i%2]);

???$linea=$this->arr[$i];

???$m=count($linea);

???for($j=0;$j

????$celdas.=sprintf("

%s","",$linea[$j]);

???$celdas.="

";

??}

??return sprintf("

",$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()."


";

$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()."


";

$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()."


";

$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()."


";

?>

總結

以上是生活随笔為你收集整理的PHP数组加表格_php数组输出html表格的操作方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。