Badger
Badger

Reputation: 487

Find available meeting slots between two times

I'm trying to work out how many meeting slots are available between two times. I'm sure I'm missing something simple with the code below as I don't often use while loops.

$start = strtotime( 'tomorrow 9am' );
$end = strtotime( 'tomorrow 9:30am' );
$length = 900;
$meetings = array();
$i = 0;

while ( $start < $end ) {
    $meetings[$i]['start'] = $start;
    $meetings[$i]['end'] = $start + $length;
    $start + $length;
    $i++;
}

It seems to be causing an infinite loop, but I can't see why.

Upvotes: 0

Views: 168

Answers (1)

Daniel Heinrich
Daniel Heinrich

Reputation: 790

It's because you don't increment the variable $start.

$start + $length;

This does nothing in itself and probably misses an equal sign. It should probably be:

$start += $length;

Upvotes: 1

Related Questions