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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Data Model Questions /

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

[SOLVED] Using FOR loop in controller


Go to End


3 Posts   709 Views

Avatar
Optic Blaze

Community Member, 190 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, 107 Posts

26 January 2014 at 3:36am

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

Avatar
Optic Blaze

Community Member, 190 Posts

26 January 2014 at 11:37am

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