PHP自学4——通过函数将数组数据输出到html的Table标签中(使用函数的例子)

  这一节其实说实话并没有什么干货,不过为了防止PO主的懒癌的复发,还是坚持放一点东西,即使是内容和长度都令人发指。这一节通过一个函数来实现将数组中的内容输出html的Table标签当中显示。

函数文件——createTables.php文件:

<?php
//convert data in array to the element displayed in html's table tag
function create_tables($dataArr, $border=1, $cellpadding=4, $cellspacing=2, $bgcolor="#FFFFFF"){
echo "<table border=\"". $border. "\" cellpadding=\"". $cellpadding.
"\" cellspacing=\"". $cellspacing. "\" bgcolor=\"". $bgcolor. "\"";
reset($dataArr);
$value = current($dataArr);
while($value){
echo "<tr><td>". $value. "</tr></td>";
$value = next($dataArr);
}
echo "</table>";
}
//create the spam data for displaying
$dataArr = array("apple", "pear", "orange");
//call the function
create_tables($dataArr, 2, 4, 2, "#CCCCCC");
?>

显示效果:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAG8AAAB9CAIAAAAjuaqnAAADfklEQVR4nO2cwZmCMBCFqYhGvHGkDRqRMjhRwjbAzYJ2D4gmIZME9gGZ8P4bjh+af5OA63OqX4KjuvoNFAVtIqFNJLSJhDaRuDZ/SmQYBtrEMAxD27ZX2pwKom1b2oSRi82HZl6vV3Y2r5lOCGgTCW0ioU0ktImENpHQJhLaRHJfm31TVXU3Qs9Jm0hoEwltItFhc+zq6kPTu0bM8taq9zWMpxVns2++ox672pDQN/boZyPLUbz6OZF12r7ZK1SDTYv1uK3lOnb1x0S8+i7afyLXdLE2l9lm2nRGbTyUWl3JtKyXZnNxOA/QdCT4eotIrVq7snd/Lsem6yTB5p65uffCo8umO1RrM1zvjK7rcNXcNxE6s7dpX2Hfi97y5V7jP1riVbtk3TnsuhXN36a1r9Xd6Jlf343VmmFJVevYeJntKpXYlAnfyRzxaScMbSKhTSS0iUS3zdygTSS0iYQ2kWRn86WcvGyWAW0iycXmKanVo8hupT94FaLNGdpEQptIaBMJbSKhTSS0iYQ2kdAmEtpEQptIFNgMh1qnKRRkjcRo50QC7ps4JTblUGsoyBqO0db1vnhMATaleGV6kDUSo4WgxKYUHEwNsvpitJiQoYVem1XTx4Ksm2K097b5nZvCHNsYo0WgxKYYapV1RmO0N7YphlrlIGssRntfm3Ko1VC1CrJGY7T3tYke+RHQJhLaREKbSBTYVARtIqFNJLSJJDubZyRWjyQvm2VAm0hysXlKavUoslvpD16FaHOGNpHQJhLaREKbSGgTCW0ioU0ktImENpHQJhItNs0AgtyQa/kyLhSCrZp+kpMORqXuejeBF+sfq8Gmk42xDz251vRestEzm8cJ/WPzt+nJbZlDieVawyFYs7p+IfPpSbHb7G2u8672SIK51ngINtQh1nwoLXarw6Y3xhVuACuGYIM2Pb9B2NI/VofNyNwUO5a6x/+0GY12Z28zZd9c7YTBXrKCzXVxno9b+sfmb9N/5fW3eF2Vfb1kJZvOT2eWtb2lf6wGm5OzbQUX9hQLwco2J/eG0nsd974LXTavYXN3aNqU2d5qmza/9I25fPf83I02LcR/B6RBm0hoEwltIqFNJNnZPCOxeiR52SwD2kRysc3n89kWxzU2i1TZXmWT/AfaREKbSGgTCW0ioU0ktImENpHQJhLaREKbSGgTCW0ioU0kfy5ZjUGTke9DAAAAAElFTkSuQmCC" alt="" />

修订于2016/3/9   By野马菌

上一篇:Java for LeetCode 125 Valid Palindrome


下一篇:Leetcode 125 Valid Palindrome 字符串处理