Insert minute by minute into function

Asked

Viewed 44 times

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:

inserir a descrição da imagem aqui

However, I am trying to insert a for minute a minute in this same function:

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 .= ':';
            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, on the screen displays like this:

inserir a descrição da imagem aqui

As I leave in the format 00:00 ?

grateful for the attention.

2 answers

3

Make an "if" within minutes "for".

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

ai you put the $min_correct variable to be displayed instead of $min

3


  • thanks, worked using sprintf function

Browser other questions tagged

You are not signed in. Login or sign up in order to post.