dmirsch Posted October 5, 2011 Share Posted October 5, 2011 This may be super simple, but it's stumping me. Is this an If/Then clause: ($month != 1 ? $month - 1 : 12) Is it saying if $month does not equal 1 then $month-1; if so, then what does the colon mean? If not, then what is this piece of code doing? Link to comment https://forums.phpfreaks.com/topic/248505-is-this-an-ifthen-clause/ Share on other sites More sharing options...
Ayon Posted October 5, 2011 Share Posted October 5, 2011 Yes that's correct except the paranteces should not wrap it all. It should be either ($month != 1) ? $month - 1 : 12; or $month != 1 ? $month -1 : 12; Link to comment https://forums.phpfreaks.com/topic/248505-is-this-an-ifthen-clause/#findComment-1276158 Share on other sites More sharing options...
djlee Posted October 5, 2011 Share Posted October 5, 2011 basically yes, its actually called a "ternary statement" $month = ($month == 1 ? 'Jan': ($month == 2 ? 'Feb' : ($menth == 3 ? 'Mar' : ($month == 4 ? 'Apr' : ( $month > 4 ? 'I got bored here' : 'Thats not right!' ))))); Link to comment https://forums.phpfreaks.com/topic/248505-is-this-an-ifthen-clause/#findComment-1276161 Share on other sites More sharing options...
dmirsch Posted October 5, 2011 Author Share Posted October 5, 2011 so the colon must be the "else" portion then. thanks everyone! Link to comment https://forums.phpfreaks.com/topic/248505-is-this-an-ifthen-clause/#findComment-1276162 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.