pithed2 Posted August 12, 2009 Share Posted August 12, 2009 Ok, I'm obviously screwing up my code, as when I var_dump the array I get nothing, so what stupid little thing am I messing up here? <?php $preseason = strtotime('2009-08-11'); $week1 = strtotime('2009-08-18'); $week2 = strtotime('2009-08-25'); $week3 = strtotime('2009-09-01'); $week4 = strtotime('2009-09-08'); $week5 = strtotime('2009-09-15'); $week6 = strtotime('2009-09-22'); $week7 = strtotime('2009-09-29'); $week8 = strtotime('2009-10-06'); $week9 = strtotime('2009-10-13'); $week10 = strtotime('2009-10-20'); $weeks_array = array($preseason, $week1, $week2, $week3, $week4, $week5, $week6, $week7, $week8, $week9, $week10); $today = strtotime(date(Y-m-d, time())); $poll_week = ''; if ($today < $weeks_array[0]) { $poll_week = 'Pre-Season'; } if ($today > $weeks_array[10]) { $poll_week = 'Closed'; } if ($poll_week == '') { for ($i=0; $i<12; $i++) { if ($today >= $week_array[$i] && $today < $week_array[$i+1]) { $poll_week = 'Week ' . $i; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/169936-dates-in-an-array/ Share on other sites More sharing options...
waterssaz Posted August 12, 2009 Share Posted August 12, 2009 The array is constructed absolutely fine its the rest of your code that is failing Quote Link to comment https://forums.phpfreaks.com/topic/169936-dates-in-an-array/#findComment-896465 Share on other sites More sharing options...
waterssaz Posted August 12, 2009 Share Posted August 12, 2009 I have fixed sytax errors and wrong variable referencing as below: <?php $preseason = strtotime('2009-08-11'); $week1 = strtotime('2009-08-18'); $week2 = strtotime('2009-08-25'); $week3 = strtotime('2009-09-01'); $week4 = strtotime('2009-09-08'); $week5 = strtotime('2009-09-15'); $week6 = strtotime('2009-09-22'); $week7 = strtotime('2009-09-29'); $week8 = strtotime('2009-10-06'); $week9 = strtotime('2009-10-13'); $week10 = strtotime('2009-10-20'); $weeks_array = array($preseason, $week1, $week2, $week3, $week4, $week5, $week6, $week7, $week8, $week9, $week10); print_r($weeks_array); $today = strtotime(date('Y-m-d', time())); echo $today; $poll_week = ''; if ($today < $weeks_array[0]) { $poll_week = 'Pre-Season'; } if ($today > $weeks_array[10]) { $poll_week = 'Closed'; } if ($poll_week == '') { for ($i=0; $i<count($weeks_array); $i++) { if ($today >= $weeks_array[$i] && $today < $weeks_array[$i+1]) { $poll_week = 'Week ' . $i; } } } echo $poll_week; ?> Quote Link to comment https://forums.phpfreaks.com/topic/169936-dates-in-an-array/#findComment-896469 Share on other sites More sharing options...
pithed2 Posted August 12, 2009 Author Share Posted August 12, 2009 Missing quotes. Gotcha. Thanks! Works fine now. Quote Link to comment https://forums.phpfreaks.com/topic/169936-dates-in-an-array/#findComment-896543 Share on other sites More sharing options...
waterssaz Posted August 13, 2009 Share Posted August 13, 2009 Just to let you know it was missing quotes but also look at how you were calling the array here: if ($today >= $week_array[$i] && $today < $week_array[$i+1]) { As I had to change it to "$weeks_array" (notice the 's') as it should have been. easy mistake to make but just thought I'd point it out. :-) Quote Link to comment https://forums.phpfreaks.com/topic/169936-dates-in-an-array/#findComment-897049 Share on other sites More sharing options...
pithed2 Posted August 13, 2009 Author Share Posted August 13, 2009 That would do it too. This is what happens when I'm forced to work outside of an IDE. Thanks again! Andy Quote Link to comment https://forums.phpfreaks.com/topic/169936-dates-in-an-array/#findComment-897479 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.