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");
?>

显示效果:

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

爱上一匹野马,可是我家里没有草原o(╯□╰)o
原文地址:https://www.cnblogs.com/yemajun/p/5257942.html