网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

如何将php数组输出html表格-创新互联

本篇内容主要讲解“如何将php数组输出html表格”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“如何将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,$) {$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="";
  $t=count($this->tit);
  for($k=0;$k<$t;$k++)
  {
   $titulos.=sprintf("%s",$this->tit[$k]);
  }
  $titulos.="";

  $celdas="";
  $n=count($this->arr);
  for($i=0;$i<$n;$i++)
  {
   $celdas.=sprintf("",$this->fons[$i%2]);
   $linea=$this->arr[$i];
   $m=count($linea);
   for($j=0;$j<$m;$j++)
    $celdas.=sprintf("%s","",$linea[$j]);
   $celdas.="";
  }
  return sprintf("

%s%s
",$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数组输出html表格”有了更深的了解,不妨来实际操作一番吧!这里是创新互联建站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!


本文标题:如何将php数组输出html表格-创新互联
网页URL:http://bjjierui.cn/article/idpsh.html

其他资讯