BigEL Posted December 22, 2012 Share Posted December 22, 2012 I'm pretty new to PHP and so far i've written a function to echo the next game in a schedule. Problem is, I want to display "Today" if there is a game today. Currently if today's date = $today, nothing gets displayed . I've tried an elseif statement inside the foreach, but with no results. If anyone could point me in the right direction, that be great. Thanks. function next_game(){ $schedule = array( 'vs. team1 ' => strtotime('17 Dec 2012'), 'vs. team2 ' => strtotime('19 Dec 2012'), '@team3 ' => strtotime('22 Dec 2012'), '@team4 ' => strtotime('4 Jan 2012') ); $today = time();// current timestamp[/background][/size][/font][/color] foreach($schedule as $place => $date){ if($date > $today) { echo date('M dS', $date)."<small>".$place."</small>"; break; } } } Output Dec 23rd<small>@FGC </small> Link to comment https://forums.phpfreaks.com/topic/272299-strtotime-issues/ Share on other sites More sharing options...
requinix Posted December 23, 2012 Share Posted December 23, 2012 What code did you try? I'm sure it just needs a small change to make it work. [edit] Actually I can guess. $today will be this very second, not just "today". Everything in $schedule will be the same too: you didn't specify a time so one will get filled in for you. So rather than compare $date with $today, compare date("Y-m-d", $date) with date("Y-m-d", $today). Link to comment https://forums.phpfreaks.com/topic/272299-strtotime-issues/#findComment-1400945 Share on other sites More sharing options...
Barand Posted December 24, 2012 Share Posted December 24, 2012 The variable $schedule exists only inside the function (read up on variable scope) so does not exist in the rest of your code. Change your function to return the array. Link to comment https://forums.phpfreaks.com/topic/272299-strtotime-issues/#findComment-1401066 Share on other sites More sharing options...
Barand Posted December 24, 2012 Share Posted December 24, 2012 today being 24th DEC, 2012, I changed your last date to 2013 and called your function next_game(); //--> Jan 04th @team4 Link to comment https://forums.phpfreaks.com/topic/272299-strtotime-issues/#findComment-1401069 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.