格式化输出数组.

function pc_grid_horizontal($array, $size) {
	$table_width = 100;
	$width = intval($table_width / $size);
	
	$tr = '<tr align="center">';
	$td = "<td width=\$width%%\">%s</td>";
	
	$grid = "<table width=\"$table_width%%\">$tr";
	
	$i = 0;
	foreach ($array as $e) {
		$grid .= sprintf($td, $e);
		$i ++;
		
		if (!$i % $size) {
			$grid .= "</tr>$tr";
		}
	}
	
	while ($i % $size) {
		$grid .= sprintf($td, ' ');
		$i ++;
	}
	
	$end_tr_len = strlen($tr) * -1;
	if (substr($grid, $end_tr_len) != $tr) {
		$grid .= '</tr>';
	} else {
		$grid = substr($grid, 0, $end_tr_end);
	}
	
	$grid .= '</table>';
	
	return $grid;
}

  

posted @ 2011-12-15 15:41  末世  阅读(352)  评论(0编辑  收藏  举报