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. eclipse代码不能自动提示的问题解决

    步骤如下:window->Preferences->Java->Editor->content assist 替换输入成: 普通:[.abcdefghijklmnopqrstu ...

  2. Eclipse工程中Java Build Path中的JDK版本和Java Compiler Compiler compliance level的区别(转)

    在这里记录一下在eclipse中比较容易搞混淆和设置错误的地方.如下图所示的功能: 最精准的解释如下: Build Path是运行时环境  Compiler是编译时环境  假设,你的代码用到泛型,Bu ...

  3. Apple激活日期查询

    需要输入的信息为苹果产品的序列号 查看您的保修服务和支持期限 - Apple 支持 或者通过果粉查询网站获取结果

  4. hdu 5389 Zero Escape (dp)

    题目:http://acm.hdu.edu.cn/showproblem.php? pid=5389 题意:定义数根:①把每一位上的数字加起来得到一个新的数,②反复①直到得到的数仅仅有1位.给定n,A ...

  5. 使用cacheBuilder时捕获内部指定异常

    由于cacheBuilder是另起线程获取,对call方法中的抛出的异常进行了封装.所以我们在最外层捕获时是无法直接指定异常类型捕获的, 获取异常的原因判断实例类型 public static voi ...

  6. POJ 2309 BST

    BST Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8565   Accepted: 5202 Description C ...

  7. 前言(CSDN也有Markdown了,好开森)

    实战出精华 在具体的C++网络编程中提升你的逼格 John Torjo Boost.Asio C++ 网络编程 Copyright © 2013 Packt Publishing 关于作者 做为一名权 ...

  8. ES7前端异步玩法:async/await理解 js原生API妙用(一)

    ES7前端异步玩法:async/await理解   在最新的ES7(ES2017)中提出的前端异步特性:async.await. 什么是async.await? async顾名思义是“异步”的意思,a ...

  9. 【HDOJ 5371】 Hotaru&#39;s problem

    [HDOJ 5371] Hotaru's problem Manacher算法+穷举/set Manacher算法一好文:http://blog.csdn.net/yzl_rex/article/de ...

  10. 如何将安卓手机中已安装的应用导出一个apk安装包

    首先安装ES文件浏览器 然后应用里找到你要导出apk的应用,长按应用,备份应用, 然后在upbacks/apps文件夹里找吧 不得不说 ES浏览器还是屌啊