Jump to:

3373 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » [SOLVED] Using FOR loop in controller

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 166 Views
  • Optic Blaze
    Avatar
    Community Member
    152 Posts

    [SOLVED] Using FOR loop in controller Link to this post

    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

  • thomas.paulson
    Avatar
    Community Member
    44 Posts

    Re: [SOLVED] Using FOR loop in controller Link to this post

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

  • Optic Blaze
    Avatar
    Community Member
    152 Posts

    Re: [SOLVED] Using FOR loop in controller Link to this post

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

    166 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.