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表格的更多相关文章

  1. C语言 数组输出,冒泡排序法,沉底排序法,二维数组输出,输出字母列长度,从随机数组中找重复数

    #include <stdio.h> #define sum 3+4//宏定义是原封不动的使用used for test4 #include <time.h>//used fo ...

  2. C语言 · 数组输出

    算法提高 数组输出   时间限制:1.0s   内存限制:512.0MB      输入一个3行4列的数组,找出该数组中绝对值最大的元素.输出该元素及其两个下标值.如有多个输出行号最小的,还有多个的话 ...

  3. Java-Runoob-高级教程-实例-数组:05. Java 实例 – 数组输出

    ylbtech-Java-Runoob-高级教程-实例-数组:05. Java 实例 – 数组输出 1.返回顶部 1. Java 实例 - 数组输出  Java 实例 以下实例演示了如何通过循环输出数 ...

  4. PHP数组输出三种形式 PHP打印数组

    PHP数组输出三种形式 PHP打印数组   $bbbb=array("11"=>"aaa","22"=>"bbb&qu ...

  5. 动手动脑,第六次Tutorial——数组和随机数数组输出及求和

    作业课后作业1 阅读QiPan.java示例程序了解如何利用二维数组和循环语句绘制五子棋盘. 首先,定义string类型的二维数组,它和类的数组不一样,类的数组分配了空间后不能直接for循环赋值,st ...

  6. javascript循环遍历数组输出key value

    javascript循环遍历数组输出key value用$.each方法肯定不行的 所以采用如下方法<pre> markers = []; markers[2]=3; markers[3] ...

  7. 【C语言】利用二维数组输出成绩

    目的:用二维数组输出下面成绩 希望你可以成为第五名童鞋! 代码: #include<stdio.h> int main() { /* 创建一个带有 4行 5 列的数组 */ ][] = { ...

  8. java数组输出的三种方式

    第一种:foreach语句遍历输出 //通过foreach语句遍历输出数组 int nums[] = new int [4]; for (int num:nums) { System.out.prin ...

  9. hive 将hive表数据查询出来转为json对象和json数组输出

    一.将hive表数据查询出来转为json对象输出 1.将查询出来的数据转为一行一行,并指定分割符的数据 2.使用UDF函数,将每一行数据作为string传入UDF函数中转换为json再返回 1.准备数 ...

随机推荐

  1. Maven添加坐标(依赖)及在Eclipse中的操作

    例如:添加一个spring-test.jar的依赖过程,普遍的做法就是直接操作pom.xml文件. 1.打开maven的中央仓库:http://search.maven.org/ 2.搜索仓库: 进入 ...

  2. GCD CoreData 简化CoreData操作(转)

    来自会员带睡帽的青蛙的分享: 短话长说,开始写这个小工具到现在有两个月了,虽然东西少,但是很精练,改了又改,期间有不少问题 在坛子里获得了不少帮助 谢谢各位大大. 就是两个文件一个类 CoreData ...

  3. 【转】supervisord使用

    Supervisor (http://supervisord.org) 是一个用 Python 写的进程管理工具,可以很方便的用来启动.重启.关闭进程(不仅仅是 Python 进程).除了对单个进程的 ...

  4. 怎么在SQL查询的结果里加行号?

    怎么在SQL查询的结果里加行号? 学习了:https://zhidao.baidu.com/question/91188037.html mysql : ) as rowNo From a, () ) ...

  5. css3 - 语言伪类选择器

    <!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8& ...

  6. Eclipse 视图

    Eclipse 视图 关于视图 Eclipse视图允许用户以图表形式更直观的查看项目的元数据. 例如,项目导航视图中显示的文件夹和文件图形表示在另外一个编辑窗口中相关的项目和属性视图. Eclipse ...

  7. Html5学习笔记1 元素 标签 属性

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. Irrlicht 3D Engine 笔记系列之 教程4 - Movement

    作者: i_dovelemon 日期: 2014 / 12 / 16 来源: CSDN 主题: Event Receiver, Animator, Framerate independent move ...

  9. solaris软件管理 FTP

    安装一些常用软件 一.应用程序与系统命令的关系: 系统命令文件位置在 /bin /sbin下面或为shell内部指令:完成对系统的基本管理工作:一般在字符操作界面中运行:一般包括命令字.命令选项和命令 ...

  10. Spring学习资料

    1.马士兵视频 2.SPRING技术内幕__深入解析SPRING架构与设计原理 3.jinnianshilongnian博客 4.Spring实战 (Spring IN Action) 5.官方文档