将PHP数组输出为HTML表格
1. [代码][PHP]代码
<?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,$) {$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 />";
http://www.huiyi8.com/clxgt/
$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 />";
将PHP数组输出为HTML表格的更多相关文章
- C语言 数组输出,冒泡排序法,沉底排序法,二维数组输出,输出字母列长度,从随机数组中找重复数
#include <stdio.h> #define sum 3+4//宏定义是原封不动的使用used for test4 #include <time.h>//used fo ...
- C语言 · 数组输出
算法提高 数组输出 时间限制:1.0s 内存限制:512.0MB 输入一个3行4列的数组,找出该数组中绝对值最大的元素.输出该元素及其两个下标值.如有多个输出行号最小的,还有多个的话 ...
- Java-Runoob-高级教程-实例-数组:05. Java 实例 – 数组输出
ylbtech-Java-Runoob-高级教程-实例-数组:05. Java 实例 – 数组输出 1.返回顶部 1. Java 实例 - 数组输出 Java 实例 以下实例演示了如何通过循环输出数 ...
- PHP数组输出三种形式 PHP打印数组
PHP数组输出三种形式 PHP打印数组 $bbbb=array("11"=>"aaa","22"=>"bbb&qu ...
- 动手动脑,第六次Tutorial——数组和随机数数组输出及求和
作业课后作业1 阅读QiPan.java示例程序了解如何利用二维数组和循环语句绘制五子棋盘. 首先,定义string类型的二维数组,它和类的数组不一样,类的数组分配了空间后不能直接for循环赋值,st ...
- javascript循环遍历数组输出key value
javascript循环遍历数组输出key value用$.each方法肯定不行的 所以采用如下方法<pre> markers = []; markers[2]=3; markers[3] ...
- 【C语言】利用二维数组输出成绩
目的:用二维数组输出下面成绩 希望你可以成为第五名童鞋! 代码: #include<stdio.h> int main() { /* 创建一个带有 4行 5 列的数组 */ ][] = { ...
- java数组输出的三种方式
第一种:foreach语句遍历输出 //通过foreach语句遍历输出数组 int nums[] = new int [4]; for (int num:nums) { System.out.prin ...
- hive 将hive表数据查询出来转为json对象和json数组输出
一.将hive表数据查询出来转为json对象输出 1.将查询出来的数据转为一行一行,并指定分割符的数据 2.使用UDF函数,将每一行数据作为string传入UDF函数中转换为json再返回 1.准备数 ...
随机推荐
- InnoDB: Warning: a long semaphore wait 解决办法
http://blog.csdn.net/wulantian/article/details/37560849
- 在C#的数据类型中,什么属于值类型,什么属于引用类型
转自原文 在C#的数据类型中,什么属于值类型,什么属于引用类型 类型:整数,浮点数,高精度浮点数,布尔,字符,结构,枚举引用类型:对象(Object),字符串,类,接口,委托,数组除了值类型和引用类型 ...
- Golang协程与通道整理
协程goroutine 不由OS调度,而是用户层自行释放CPU,从而在执行体之间切换.Go在底层进行协助实现 涉及系统调用的地方由Go标准库协助释放CPU 总之,不通 ...
- lstm作的第一首诗,纪念
黄獐春风见破黛,十道奇昌犹自劳. 开领秦都色偏早,未知长柳是来恩. 争时欲下花木湿,早打红筵枝上香. 酣质矫胶麦已暮,丝窗瑞佩满含龙. 感觉有点意思哈,花木对应枝上,还有点对仗的意味. 于是接着又弄了 ...
- 【Hibernate步步为营】--核心对象+持久对象全析(三)
上篇文章讨论了Hibernate持久对象的生命周期,在整个生命周期中一个对象会经历三个状态,三种状态的转换过程在开发过程中是可控的.并且是通过用法来控制它们的转化过程.详细的转化过程今天就来着重讨论下 ...
- 可在 html5 游戏中使用的 js 工具库
可在 html5 游戏中使用的 js 工具库 作者: 木頭 时间: September 21, 2014 分类: Utilities,Game 使用 cocos2d-js 3.0 开发游戏项目两三个月 ...
- Python遍历列表
#循环遍历列表 nums = [ss,gg,e,fff,bb] #while循环遍历,但是不推荐使用,因为还要把列表的元素数出来 i = 0 while i<5: print(nums[i]) ...
- Vue.directive 自定义指令
一.什么是全局API? 全局API并不在构造器里,而是先声明全局变量或者直接在Vue上定义一些新功能,Vue内置了一些全局API,比如我们今天要学习的指令Vue.directive.说的简单些就是,在 ...
- 生产追溯系统-Wifi+传感器,实现计数器以及监控机器是否停止
物联网听上去是一个高大上的词儿,还有什么大数据.云.智能制造等等,今天我也往这方面稍微靠一靠,这篇文章主要介绍的是通过 wifi 模块与传感器组合,实现感应计数器,应用场景主要如下: 1.统计 SMT ...
- listview 下拉刷新
http://blog.csdn.net/lancees/article/details/7776853