.evo. Posted December 30, 2008 Share Posted December 30, 2008 This is more of an experiment than anything, but I was making a function so that you enter a year as the variable, and if the year you entered was the current year, it would just echo the current year. If not it would echo the year chosen - current year. eg. "cpyrht(2003);" would show up as "2003 - 2008" but if you entered "cpyrht(2008);" it would show up as "2008" because it is the current year. Anyway the code I have at the moment, is not working, it's not a syntax error it's just not functioning. Wherever I enter the function the div that it's placed in just disappears. $curyr = date(Y); function cpyrht($yr) { $cpyrht = ($yr==$curyr)?"$yr":"$yr - $curyr"; echo $cpyrht; } Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/138850-solved-comparison-operators-experiment-need-help/ Share on other sites More sharing options...
Mchl Posted December 30, 2008 Share Posted December 30, 2008 $curyr has to be defined within function. Read on variable scope in manual function cpyrht($yr) { $curyr = date(Y); $cpyrht = ($yr==$curyr)?"$yr":"$yr - $curyr"; return $cpyrht; } echo cpyrht("2008"); echo cpyrht("2003"); Quote Link to comment https://forums.phpfreaks.com/topic/138850-solved-comparison-operators-experiment-need-help/#findComment-726060 Share on other sites More sharing options...
.evo. Posted December 30, 2008 Author Share Posted December 30, 2008 It's still doing the same thing. ??? Quote Link to comment https://forums.phpfreaks.com/topic/138850-solved-comparison-operators-experiment-need-help/#findComment-726064 Share on other sites More sharing options...
.evo. Posted December 30, 2008 Author Share Posted December 30, 2008 Ok I just got the function working in an if statement. Now I just gotta try get that into a working comparison operator. function cpyrht($yr) { $sep = " - "; $curyr = date(Y); if ($yr==$curyr) { echo $curyr; } else { echo $yr, $sep, $curyr; } } cpyrht("2003"); cpyrht("2008"); Quote Link to comment https://forums.phpfreaks.com/topic/138850-solved-comparison-operators-experiment-need-help/#findComment-726073 Share on other sites More sharing options...
Mchl Posted December 30, 2008 Share Posted December 30, 2008 I tested the code I posted and it works fine. Quote Link to comment https://forums.phpfreaks.com/topic/138850-solved-comparison-operators-experiment-need-help/#findComment-726082 Share on other sites More sharing options...
.evo. Posted December 30, 2008 Author Share Posted December 30, 2008 It's not for me. :S EDIT: I just tried it for a 3rd time and it worked, that's very strange. Thanks though. Quote Link to comment https://forums.phpfreaks.com/topic/138850-solved-comparison-operators-experiment-need-help/#findComment-726083 Share on other sites More sharing options...
Mchl Posted December 30, 2008 Share Posted December 30, 2008 Stuff like that happens all the time. You might forgot to save your changes, did not refresh browser cache, etc... I'm loosing several minutes each day in trivialities like that Quote Link to comment https://forums.phpfreaks.com/topic/138850-solved-comparison-operators-experiment-need-help/#findComment-726089 Share on other sites More sharing options...
.evo. Posted December 30, 2008 Author Share Posted December 30, 2008 Sometimes FireFTP gets a bit dicky with saving files, well at least it's working now. Quote Link to comment https://forums.phpfreaks.com/topic/138850-solved-comparison-operators-experiment-need-help/#findComment-726147 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.