.Maui Blog

PHP | Convert an array to an html table

function att($arr, $class = null) {
	
	$return = "<table" . (!is_null($class) ? ' class = "' . $class . '"' : null) . ">";
	
	foreach ($arr as $key => $value) {
		
		$return .= "<tr>";
		
		foreach ($value as $cell) {
			$return .= "<td>" . $cell . "</td>";			
		}
		
		$return .= "</tr>";
		
	}
	
	$return .= "</table>";
	
	return $return;
	
}
Exit mobile version