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;
	
}

Leave a Comment

Your email address will not be published. Required fields are marked *