Aureole Posted January 19, 2008 Share Posted January 19, 2008 Will it work if I change this: <?php if($friendCount == 0) { $friendText = 'My Friends'; } else { $friendText = ($friendCount == 1) ? '1 Friend Online' : $friendCount.' Friends Online'; } ?> ...into this: <?php $friendText = ($friendCount == 0) ? 'My Friends' : ($friendCount == 1) ? '1 Friend Online' : $friendCount.' Friends Online'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/86752-will-this-work/ Share on other sites More sharing options...
roopurt18 Posted January 19, 2008 Share Posted January 19, 2008 Well, you could just try it and see. But what's the point? That doesn't make it run any faster and it just becomes harder to read IMO. Quote Link to comment https://forums.phpfreaks.com/topic/86752-will-this-work/#findComment-443408 Share on other sites More sharing options...
Aureole Posted January 19, 2008 Author Share Posted January 19, 2008 If I nested any more than 2 then it becomes harder to read (if it is possible to nest them), but it does make my file shorter and I assume it doesn't take PHP LONGER to go through this... plus with portions of code like this which I know are never going to change even as I continue to develop whatever I may be developing - it doesn't really matter how readable it is as far as I'm concerned. Quote Link to comment https://forums.phpfreaks.com/topic/86752-will-this-work/#findComment-443410 Share on other sites More sharing options...
Aureole Posted January 19, 2008 Author Share Posted January 19, 2008 I tested it and while I received no errors, something didn't seem to be working right. It would show me as having 1 New Message and 1 Friend Online even though that isn't true. Could you just let me know if it should work as I have tried it like you said and I just don't know. Quote Link to comment https://forums.phpfreaks.com/topic/86752-will-this-work/#findComment-443413 Share on other sites More sharing options...
Daniel0 Posted January 19, 2008 Share Posted January 19, 2008 1) You cannot know if you want to change something later. 2) The amount of saved space is negligible. 3) It takes longer to other people to read. I don't think it's worth nesting ternary operators. Quote Link to comment https://forums.phpfreaks.com/topic/86752-will-this-work/#findComment-443429 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.