Enter minute by minute in function

3

I have the following php function below:

function showComboHorarios($name, $default = '08:00') {
$hi = 6;  // hora inicial
$hf = 23; // hora final
?>
<select style="width: 80px;" name="<?php echo $name; ?>">
    <?php
    for ($i = $hi; $i <= $hf; $i++) {
        $h = ($i < 10) ? '0' . $i : $i;
        $h .= ':';
        ?>
        <option value="<?php echo $h . '00'; ?>"<?php echo ($default == $h . '00') ? ' selected' : ''; ?>><?php echo $h . '00'; ?></option>
        <option value="<?php echo $h . '30'; ?>"<?php echo ($default == $h . '30') ? ' selected' : ''; ?>><?php echo $h . '30'; ?></option>
        <?php
    }
    ?>
</select>
<?php
}

and then displays the screen:

However,I'mtryingtoinsertaminutebyminuteinthesamefunction:

functionshowComboHorarios($name,$default='08:00'){$hi=6;//horainicial$hf=23;//horafinal?><selectstyle="width: 80px;" name="<?php echo $name; ?>">
    <?php
    for ($i = $hi; $i <= $hf; $i++) {
        $h = ($i < 10) ? '0' . $i : $i;
        $h .= ':';
            for ($min = 0; $min< 59; $min++){ 
        ?>
                <option value="<?php echo $h . $min  ?>"<?php echo ($default == $h . $min ) ? ' selected' : ''; ?>><?php echo $h . $min  ?></option>
                <option value="<?php echo $h . $min ?>"<?php echo ($default == $h . $min) ? ' selected' : ''; ?>><?php echo $h . $min; ?></option>
        <?php
            }//for mminuto
    }
    ?>
</select>
<?php
}

however, the screen displays like this:

How do I leave the 00:00 format?

Thank you for your attention.

    
asked by anonymous 11.06.2015 / 14:54

2 answers

3

Format the time this way: link

sprintf ('% 02d:% 02d', $ h, $ min);

    
11.06.2015 / 15:24
3

Make an "if" within the "for" of the minutes.

if ($min < 10) {
    $min_correto = '0' . $min
} else {
    $min_correto = $min;
}

There you put the variable $ min_correto to be displayed instead of $ min

    
11.06.2015 / 15:12