コード例 #1
0
ファイル: html helper.php プロジェクト: kayeaborot/Codes
class HTML_Helper
{
    public function print_table($names)
    {
        echo "<table><tr>";
        foreach ($names as $key => $value) {
            echo "<th>" . $key . "</th>";
        }
        echo "</tr><tr>";
        foreach ($names as $key => $value) {
            echo "<td>" . $value . "</td>";
        }
        echo "</table>";
    }
    public function print_select($s, $states)
    {
        echo "<form>";
        echo "<select name='" . $s . "'>";
        foreach ($states as $state) {
            echo "<option value='" . $state . "'>" . $state . "</option>";
        }
        echo "</select>";
        echo "</form>";
    }
}
$names = array("first_name" => "Michael", "last_name" => "Choi", "nick_name" => "Sensei");
$states = array("CA", "WA", "UT", "TX", "AZ", "NY");
$try1 = new HTML_Helper();
$try2 = new HTML_Helper();
echo $try1->print_table($names);
echo $try2->print_select("state", $states);
コード例 #2
0
<div id="wrapper">

    <h1>HTML Helper - Coding Dojo Assignment</h1>


    <h3>HTML Generated by the <em>print_table</em> Method<br />of the <em>HTML_Helper</em> Class</h3>
    <?php 
// Instantiate a $generateUsersTable object
$generateUsersTable = new HTML_Helper();
// Call the print_table method and
// pass in the $users array to generate HTML
$generateUsersTable->print_table($users);
?>

    <h3>HTML Generated by the <em>print_select</em> Method<br />of the <em>HTML_Helper</em> Class</h3>

    <?php 
// Instantiation a $generalSelectTag object
$generalSelectTag = new HTML_Helper();
// Call the print_select method and
// pass in the $states array to generate HTML
$generalSelectTag->print_select($states);
?>


    

</div>

</body>
</html>