创建类以及引用一个类

 

<?php

class Table {

private $row;
private $col;
private $border;
private $width;


public function __construct($row, $col, $border, $width) {
$this->row = $row;
$this->col = $col;
$this->border = $border;
$this->width = $width;
}

public function create_table($row, $col, $border, $width) {
header("content-type:text/html; charset=utf-8");
$data = '<table border="'.$this->border.'" width="'.$this->width.'">';
for($row = 0; $row<$this->row; $row++) {
$data .= '<tr>';
for($col = 0; $col<$this->col; $col++) {
$data .= '<td>'.($row+1).'行'.($col+1).'列'.'</td>';
}
$data .= '</tr>';
}
$data .= '</table>';


return $data;
}

}

$table = new Table(5, 5, 2, 800);
echo $table->create_table();

 


?>

posted @ 2015-11-18 18:10  花间草  阅读(214)  评论(0编辑  收藏  举报