jd2007 Posted July 21, 2007 Share Posted July 21, 2007 Is there a shorter way of doing if...else statement...i know there is one..how to do it? Quote Link to comment https://forums.phpfreaks.com/topic/61083-is-there-a-shorter-way-of-doing-ifelse-statement/ Share on other sites More sharing options...
DeadEvil Posted July 21, 2007 Share Posted July 21, 2007 ternary operation... $var = !empty($var) : $var = 'not empty' ? $var = 'empty'; Quote Link to comment https://forums.phpfreaks.com/topic/61083-is-there-a-shorter-way-of-doing-ifelse-statement/#findComment-303986 Share on other sites More sharing options...
jd2007 Posted July 21, 2007 Author Share Posted July 21, 2007 thanks... Quote Link to comment https://forums.phpfreaks.com/topic/61083-is-there-a-shorter-way-of-doing-ifelse-statement/#findComment-303987 Share on other sites More sharing options...
burtybob Posted July 21, 2007 Share Posted July 21, 2007 You can use switch as well, http://us2.php.net/switch Quote Link to comment https://forums.phpfreaks.com/topic/61083-is-there-a-shorter-way-of-doing-ifelse-statement/#findComment-303991 Share on other sites More sharing options...
jd2007 Posted July 21, 2007 Author Share Posted July 21, 2007 deadevil, your code is wrong, its actually : $var = !empty($var) ? $var = 'not empty' : $var = 'empty'; Quote Link to comment https://forums.phpfreaks.com/topic/61083-is-there-a-shorter-way-of-doing-ifelse-statement/#findComment-303996 Share on other sites More sharing options...
Barand Posted July 21, 2007 Share Posted July 21, 2007 Both wrong $var = !empty($var) ? 'not empty' : 'empty'; Quote Link to comment https://forums.phpfreaks.com/topic/61083-is-there-a-shorter-way-of-doing-ifelse-statement/#findComment-304021 Share on other sites More sharing options...
burtybob Posted July 21, 2007 Share Posted July 21, 2007 just use switch seems like its the easiest and least complicated way of doing it! Quote Link to comment https://forums.phpfreaks.com/topic/61083-is-there-a-shorter-way-of-doing-ifelse-statement/#findComment-304065 Share on other sites More sharing options...
wildteen88 Posted July 21, 2007 Share Posted July 21, 2007 just use switch seems like its the easiest and least complicated way of doing it! ternary operation is far better if you are only comparing one value. You'd use switch if you are going to be comparing multiple values. Quote Link to comment https://forums.phpfreaks.com/topic/61083-is-there-a-shorter-way-of-doing-ifelse-statement/#findComment-304144 Share on other sites More sharing options...
burtybob Posted July 21, 2007 Share Posted July 21, 2007 just use switch seems like its the easiest and least complicated way of doing it! ternary operation is far better if you are only comparing one value. You'd use switch if you are going to be comparing multiple values. oh... Ok thanks for that little bit of information i will remember that now! Quote Link to comment https://forums.phpfreaks.com/topic/61083-is-there-a-shorter-way-of-doing-ifelse-statement/#findComment-304206 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.