You are setting the variables $days
etc inside a function, but are expecting to access them outside that functions. This cannot be done, as the variables do not have the correct scope.
The smallest change you can make to see it work is this:
function countdown($year, $month, $day, $hour, $minute){
global $days, $hours, $minutes; // ADD THIS
$the_countdown_date=mktime($hour, $minute, 0, $month, $day, $year, -1);
$today=time();
$difference=$the_countdown_date - $today;
$days=floor($difference/60/60/24);
$hours=floor(($difference - $days*60*60*24)/60/60);
$minutes=floor(($difference - $days*60*60*24 - $hours*60*60)/60);
}
This works because it makes your variables have global scope. However, it's the wrong solution.
The better solution would be to have your function return the values you need -- and since there are three values but only one return, do so with an array:
function countdown($year, $month, $day, $hour, $minute){
$the_countdown_date=mktime($hour, $minute, 0, $month, $day, $year, -1);
$today=time();
$difference=$the_countdown_date - $today;
$days=floor($difference/60/60/24);
$hours=floor(($difference - $days*60*60*24)/60/60);
$minutes=floor(($difference - $days*60*60*24 - $hours*60*60)/60);
return array($days, $hours, $minutes);
}
And then, call the function and retrieve the values like this:
list($days, $hours, $minutes) = countdown(2011,6,7,7,31,0);
There are many variations on the "return multiple values in an array" theme; I have used the shortest (but perhaps not the most clear, because it uses list
) here.