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; } } Quote 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"; } ?> Quote 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 Quote 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. Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.