Timer
2009-03-28 01:03:52
Ok… pretend the account timer was made…. (m-d-Y format)
03-20-2009
if the account has been made for more then 30 days… then have a function return the word "done" … if its not been 30 days… have it return the remaining days till 30 days is up.. is that too hard to ask? :redface:
and can it read the dates from a array please? like
"Timer" => "03-20-2009"
"Hexinist" => "03-21-2009"
Code pl0x? I've tried and failed.. thanks in advance!
nielsie95
2009-03-28 04:27:23
<?php
$arr["Timer"] = "03-20-2009";
$arr["Hexinist"] = "03-21-2009";
$arr["nielsie95"] = "02-21-2009";
foreach ($arr as $name => $d) {
$ardate = explode("-", $d);
$tdate = mktime(0, 0, 0, $ardate[0], $ardate[1], $ardate[2]);
$togo = 30 - floor((time() - $tdate) / (60 * 60 * 24));
echo "$name => ".(($togo <= 0) ? "done" : "$togo days to go")."<br \>\n";
}
?>
Bobarkinator
2009-03-28 05:06:29
wow looks like PHP tags need some work.
Wizzup?
2009-03-28 09:20:09
From: Bobarkinator
wow looks like PHP tags need some work.
Blame GeSHi, but I recon I can fix it myself.
Bobarkinator
2009-03-28 12:51:24
From: Wizzup?
Blame GeSHi, but I recon I can fix it myself.
Weird, I thought GeShi was pretty stable, no?
nielsie95
2009-03-30 02:59:23
You can't access the array inside the function..
function DaysLeft($name, $arr) {
$ardate = explode("-", $arr[$name]);
$tdate = mktime(0, 0, 0, $ardate[0], $ardate[1], $ardate[2]);
$togo = 30 - floor((time() - $tdate) / (60 * 60 * 24));
if (togo <= 0) {
return "done";
exit;
} else {
return $togo;
}
}
echo DaysLeft("Timer", $arr);
Timer
2009-03-30 16:09:39
oh, lol, thanks! :D
EDIT -
Now.. its really messed up.. no matter what, it returns done..
[PHP]<?php
$arr["Timer"] = "03-10-2009";
$arr["Hexinist"] = "03-21-2009";
function DaysLeft($name, $arr) {
$ardate = explode("-", $arr[$name]);
$tdate = mktime(0, 0, 0, $ardate[0], $ardate[1], $ardate[2]);
$togo = 30 - floor((time() - $tdate) / (60 * 60 * 24));
if (togo <= 0) {
return "done";
} else {
return $togo;
}
}
echo DaysLeft("Timer", $arr);
?>[/PHP]
nielsie95
2009-03-31 09:29:33
How long did you try it for yourself..? :\
if ($togo <= 0) {
Timer
2009-03-31 16:35:05
lol, wow.. i totally didn't notice that… :o