busillis Posted June 21, 2008 Share Posted June 21, 2008 These are both in the same php file, I am expecting it to state "day exceeded", as this month ends on the 30th - I have verified this by echoing too... I know it must be something silly, just scratching my head here if (dayofMonthExceeded("31") == true) { echo "day exceeded"; } else { echo "day NOT exceeded"; } function dayofMonthExceeded($givenDay) { if ($givenDay > date("t",$t)) { return true; } else { return false; } } Link to comment https://forums.phpfreaks.com/topic/111239-solved-custom-function-not-returning-correct-value/ Share on other sites More sharing options...
thebadbad Posted June 21, 2008 Share Posted June 21, 2008 What's inside $t? Just remove it if you want to compare with the current month: <?php function dayofMonthExceeded($givenDay) { if ($givenDay > date("t")) { return true; } else { return false; } } ?> And you won't need to compare what's returned with true: <?php if (dayofMonthExceeded("31")) { echo "day exceeded"; } else { echo "day NOT exceeded"; } ?> Link to comment https://forums.phpfreaks.com/topic/111239-solved-custom-function-not-returning-correct-value/#findComment-570921 Share on other sites More sharing options...
busillis Posted June 21, 2008 Author Share Posted June 21, 2008 $t=time(); It works now, brilliant! Thanks for your help. Really appreciated Link to comment https://forums.phpfreaks.com/topic/111239-solved-custom-function-not-returning-correct-value/#findComment-570923 Share on other sites More sharing options...
thebadbad Posted June 21, 2008 Share Posted June 21, 2008 Good. If you wonder why it didn't work, it was because $t was defined outside the function, making it unavailable to the function. Link to comment https://forums.phpfreaks.com/topic/111239-solved-custom-function-not-returning-correct-value/#findComment-570925 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.