Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 循环和小时数_Php_Loops - Fatal编程技术网

Php 循环和小时数

Php 循环和小时数,php,loops,Php,Loops,所以我得到了这个剧本: <select class="n-select" name="heure-event" id="heure-event"> <option selected="selected"></option> <?php for ( $heures = 0 ; $heures <= 23 ; $heures++ ){ for ( $minutes = 0 ; $minutes &

所以我得到了这个剧本:

<select class="n-select" name="heure-event" id="heure-event">
    <option selected="selected"></option>
    <?php
        for ( $heures = 0 ; $heures <= 23 ; $heures++ ){
            for ( $minutes = 0 ; $minutes <= 45 ; $minutes += 15 ){ 
    ?>
    <option value="<?php echo $heures.':'.$minutes;?>:00">
        <?php
            echo $heures.':'.$minutes;
        ?>
    </option>   
    <?php
            }
        }
    ?>                    
</select>

它工作得很好,但有一个小问题:1:15,1:0,等等

我要:01:15和1:00

有人能帮我吗?我可能需要检查
$I
是否为
<10
,然后添加
'0.$I'
或类似的内容?

使用

使用


这只是一个显示问题。不要存储“格式化”数据,尤其是数字数据

所以。。。对于值,存储1:15,但显示01:15,通过

value="<?php echo "$heure:$minutes" ?>"><?php echo sprintf('%02d:%02d', $heures, $minutes) ?></option>
value=”“>

那只是一个显示问题。不要存储“格式化”数据,尤其是数字数据

所以。。。对于值,存储1:15,但显示01:15,通过

value="<?php echo "$heure:$minutes" ?>"><?php echo sprintf('%02d:%02d', $heures, $minutes) ?></option>
value=”“>

查看它返回格式化字符串查看它返回格式化字符串
$heures = sprintf('%02d', $heures);
$minutes= sprintf('%02d', $minutes);
<option value="<?php echo $heures.':'.$minutes;?>:00"><?php echo $heures.':'.$minutes;?></option>
value="<?php echo "$heure:$minutes" ?>"><?php echo sprintf('%02d:%02d', $heures, $minutes) ?></option>
                                <option value="<?php echo sprintf('%02d:%02d', $heures, $minutes) ?>:00"><?php echo sprintf('%02d:%02d', $heures, $minutes) ?></option>