PHP函数只能正常工作一次

时间:2015-06-03 19:02:12

标签: javascript php html5 twitter-bootstrap

我有一个php函数,它生成要在选择菜单中使用的html代码。计划是使用此功能为总共4个不同的选择菜单生成相同的选项。该功能第一次完美运行,但是当我第二次再次调用php函数时,我遇到的问题就出现了,它只回显了前四个值(关闭,生病,假期,假期)。知道这里发生了什么吗?

PHP

function generateTimes()
{
    echo "<option value='off'>OFF</option>";
    echo "<option value='sick'>SICK</option>";
    echo "<option value='holiday'>HOLIDAY</option>";
    echo "<option value='vacation'>VACATION</option>";

    function generateHoursMinutes($meridiem, $start, $end)
    {
        for($hour=$start; $hour<=$end; $hour++)
        {
            for($minute=0; $minute<=45;$minute+=15)
            {
                if($minute == 0)
                {
                    $onTheHour = "00";
                    $time = $hour.":".$onTheHour.$meridiem;
                    $showTime = $hour.":".$onTheHour." ".$meridiem;
                }
                else
                {
                    $time = $hour.":".$minute.$meridiem;
                    $showTime = $hour.":".$minute." ".$meridiem;
                }
                echo "<option value='$time'>$showTime</option>";
            }
        }
    }

    generateHoursMinutes('AM', 6, 11);
    echo "<option value='12:00PM'>12:00 PM</option>";
    echo "<option value='12:15PM'>12:15 PM</option>";
    echo "<option value='12:30PM'>12:30 PM</option>";
    echo "<option value='12:45PM'>12:45 PM</option>";
    generateHoursMinutes('PM', 1, 10);
    echo "<option value='11:00PM'>11:00 PM</option>";
}

HTML

<div class="form-group">
    <label for="inputTimeIn">Time In</label>
    <select class="form-control" id="inputTimeIn" name="inputTimeIn">
        <?php
            generateTimes();
        ?>
    </select>
</div>

<div class="form-group">
    <label for="inputTimeOut">Time Out</label>
    <select class="form-control" id="inputTimeOut" name="inputTimeOut">
        <?php
            generateTimes();
        ?>
    </select>
</div>

0 个答案:

没有答案