Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions /

[SOLVED] Using FOR loop in controller


Reply


3 Posts   347 Views

Avatar
Optic Blaze

Community Member, 165 Posts

26 January 2014 at 12:37am

Hi there,

I want to dynamically create a list of times that will be used in an array to populate a drop down menu with times in half hour increments. It looks like this so far:

      // Times drop down array
      for($count = 1; $count <=8; $count++) {
      $starttime1 = strtotime("08:00");
      $interval = 30;   
      $times = array(date("H:i", strtotime('+'.($count*$interval).'minutes', $starttime1)));   
      }

When i do a 'print_r($times)' it prints:
Array ( [0] => 12:00 )
instead of
Array ( [0] => 08:00, [1] => 08:30, [3] => 09:00, [4] => 09:30...... )

What am i doing wrong

Avatar
thomas.paulson

Community Member, 82 Posts

26 January 2014 at 3:36am

$times[] = date("H:i", strtotime('+'.($count*$interval).'minutes', $starttime1));

Avatar
Optic Blaze

Community Member, 165 Posts

26 January 2014 at 11:37am

Thanks for that...worked like a charm. Cant believe i did not think of it.