PHP Classes

File: 03_custom_function_classes.php

Recommend this page to a friend!
  Classes of Alexandre Sinício   PHP Array into HTML Table   03_custom_function_classes.php   Download  
File: 03_custom_function_classes.php
Role: Example script
Content type: text/plain
Description: Example - Defining classes to elements through custom functions
Class: PHP Array into HTML Table
Generate HTML tables from data in arrays
Author: By
Last change:
Date: 7 years ago
Size: 934 bytes
 

Contents

Class file image Download
<?php
   
use alesinicio\HTMLTable;

    require
"../HTMLTable.php";
   
   
$arrHeaders = array(
       
"First column", "Second column", "Third column", "Fourth column"
   
);
   
   
$arrData = array(
        array(
"this", "is", "first", "row"),
        array(
"could", "come", "from", "database")
    );
   
   
$tdClassesFunction = function($value) {
        if (
$value == "this") {
            return
"red";
        } else {
            return
null;
        }
    };
   
   
$trClassesFunction = function($row) {
        if (
$row[1] == "come") {
            return
"blue";
        } else {
            return
"green";
        }
    };
   
   
$table = new HTMLTable();
   
$table->setData($arrData);
   
$table->setHeaders($arrHeaders);
   
$table->setTdClassFunction($tdClassesFunction);
   
$table->setTrClassFunction($trClassesFunction);
    echo
$table->getHTML();
   
    echo
"<style>
        .red{background-color: red;}
        .green{background-color: green;}
        .blue{background-color: blue;}
        .grey{background-color: grey;}
        </style>"
;