wright67uk Posted September 6, 2011 Share Posted September 6, 2011 Which of the below syntax is the better to be using? $bal = 100; if($bal > 100) { echo "you have over 100 pounds; } else { echo "you have less than 100 pounds"; } if ($bal > 100); echo "you have over than 100"; else ; echo "you have less than 100"; endif; Quote Link to comment https://forums.phpfreaks.com/topic/246513-syntax-v-alternative-syntax/ Share on other sites More sharing options...
Pikachu2000 Posted September 6, 2011 Share Posted September 6, 2011 I prefer this one, actually. echo $bal > 100 ? 'You have over 100 pounds.' : 'You have less than 100 pounds.'; Quote Link to comment https://forums.phpfreaks.com/topic/246513-syntax-v-alternative-syntax/#findComment-1265818 Share on other sites More sharing options...
Alex Posted September 6, 2011 Share Posted September 6, 2011 That's not the alternative syntax. This is: if ($bal > 100): echo "you have over than 100"; else: echo "you have less than 100"; endif; How do you define "better"? Quote Link to comment https://forums.phpfreaks.com/topic/246513-syntax-v-alternative-syntax/#findComment-1265819 Share on other sites More sharing options...
wright67uk Posted September 6, 2011 Author Share Posted September 6, 2011 I prefer this one, actually. echo $bal > 100 ? 'You have over 100 pounds.' : 'You have less than 100 pounds.'; Well they don't teach that in my text books! Brilliant none the less. What's best a freak or an addict.? Quote Link to comment https://forums.phpfreaks.com/topic/246513-syntax-v-alternative-syntax/#findComment-1265851 Share on other sites More sharing options...
flappy_warbucks Posted September 6, 2011 Share Posted September 6, 2011 This question really is subjective. Personally, i prefer: if($bal > 100) { echo "you have over 100 pounds; } else { echo "you have less than 100 pounds"; } I find that it makes reading the code easier. But not everyone agrees. Quote Link to comment https://forums.phpfreaks.com/topic/246513-syntax-v-alternative-syntax/#findComment-1265866 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.