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. 第1章 Spring Cloud 构建微服务架构(一)服务注册与发现

      一.Spring Cloud 简介 Spring Cloud是一个基于Spring Boot实现的云应用开发工具,它为基于JVM的云应用开发中的配置管理.服务发现.断路器.智能路由.微代理.控制总 ...

  2. php curl xml传输和转换

    <?php /** * API * User: sgfoot * Date: 2017/3/20 * Time: 18:05 */ class apiCurl { private $config ...

  3. javascript --- 移除DOM节点

    在IE中移除容器类节点,会引起内存泄露,最好是创建一个新的节点,比如div,然后将要删除的节点放入这个div中,再将div的innerHTML清空.其它的直接removeChild就可以了. var ...

  4. OpenGL step to step(2)

    这是一个类似于地球绕太阳旋转的demo 原有的例子是用键盘接受事件,我做了修改,使用了timer把他变成一个动态旋转的 #import <Foundation/Foundation.h> ...

  5. 进程间通信IPC、LPC、RPC

    进程间通信(IPC,Inter-Process Communication),指至少两个进程或线程间传送数据或信号的一些技术或方法.进程是计算机系统分配资源的最小单位.每个进程都有自己的一部分独立的系 ...

  6. 很多shell命令后面的单横杠和双横杠,原来这个意思

    原文: https://blog.csdn.net/deyili/article/details/5471023 ------------------------------------------- ...

  7. How to set the initial value of a select element using AngularJS ng-options & track by

    原文: https://www.gurustop.net/blog/2014/01/28/common-problems-and-solutions-when-using-select-element ...

  8. C中的预编译编译链接

        http://ke.qq.com/webcourse/index.html#course_id=67888&term_id=100058920&taid=13934591901 ...

  9. xml实现AOP

    1.使用<aop:config></aop:config> 2.首先我们需要配置<aop:aspect></aop:aspect>,就是配置切面 2.1 ...

  10. Audio原理图设计

    1.DMIC 1)当双MIC时,通过MIC上的Selection PIN脚PULL  U/D进行左右channel选择.