theredking Posted September 5, 2007 Share Posted September 5, 2007 I'm desperately trying to grasp this simple concept... I can make it work in its simplest forms, but as I try to get more complicated things start to go wrong. If I have a basic if, elseif, else statement: if () { do something } elseif () { do something else } else () { do another thing } Can I add additional "ifs" inside of this? I want to have multiple ifs to echo my form results based on what is inputted into the form. So, if one thing is inputted, I want to echo certain results, but then instead of an elseif something else, I want to echo something else as well "if" something else is inputted or selected. I'm sure this doesn't make too much sense... I'd post my code, but it's a fair bit of a mess, and would take quite a long time to explain. Is there a great if elseif tutorial anyone could point me to? Quote Link to comment https://forums.phpfreaks.com/topic/68071-solved-if-elseif-else-help/ Share on other sites More sharing options...
Crow Posted September 5, 2007 Share Posted September 5, 2007 You can nest conditionals. <?php if(condition) { do this; if(some other condition) { do this if condition and some other condition is true; } } elseif (some other condition) { do this; } else { fall back on this; ?> } You can also use a shorter form of conditionals (condition) ? true : false So, for example say you have this. (This is a bad example) <?php $rose = 'red'; if($rose) { //check to see if $rose is true echo 'The rose is '. ($rose == red) ? 'red' : 'blue'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/68071-solved-if-elseif-else-help/#findComment-342155 Share on other sites More sharing options...
theredking Posted September 5, 2007 Author Share Posted September 5, 2007 Cool thanks! Quote Link to comment https://forums.phpfreaks.com/topic/68071-solved-if-elseif-else-help/#findComment-342161 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.