jim.davidson Posted January 31, 2012 Share Posted January 31, 2012 I'm a little new to this and inherited some code. I see this line of code but I don't know what it's suppose to do. if(date(s)%2 == 0) Can someone explain it to me? I'm thinking the s should be in quotes and I don't know what the %2 does Any guidance will be appreciated Quote Link to comment https://forums.phpfreaks.com/topic/256119-what-does-this-date-code-do/ Share on other sites More sharing options...
ManiacDan Posted January 31, 2012 Share Posted January 31, 2012 the 's' should be in quotes, yes. % is the modulous operator This line basically says "only execute the following code on even-numbered seconds." I don't know why they'd want that. I also don't know why they used 's' instead of the more correct 'U' Quote Link to comment https://forums.phpfreaks.com/topic/256119-what-does-this-date-code-do/#findComment-1312954 Share on other sites More sharing options...
jim.davidson Posted January 31, 2012 Author Share Posted January 31, 2012 Thank you very much, the code displays one image if even then another if odd. what I can't understand is why it worked as is before I inherited it, where now I get an error on the if(date(s) say it wants to know what s is. That's why I thought it needed the quotes. Quote Link to comment https://forums.phpfreaks.com/topic/256119-what-does-this-date-code-do/#findComment-1312961 Share on other sites More sharing options...
ManiacDan Posted January 31, 2012 Share Posted January 31, 2012 It should have always generated a warning, it's poorly written. You may have enabled errors or upgraded your server or whatever to generate the error. All strings need to be quoted, or you'll get an undefined constant error. Quote Link to comment https://forums.phpfreaks.com/topic/256119-what-does-this-date-code-do/#findComment-1312966 Share on other sites More sharing options...
jim.davidson Posted January 31, 2012 Author Share Posted January 31, 2012 Maniac Dan, Thank you very much I've been pulling my hair out trying to figure out why this code ran before but wouldn't run once we transfered it over to our server. Evidently the server that it resided on before hasn't been updated. There's lots of work to do, errors pop up everywhere. I might just rewrite the whole thing. Quote Link to comment https://forums.phpfreaks.com/topic/256119-what-does-this-date-code-do/#findComment-1312969 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.