mathisjr Posted March 5, 2009 Share Posted March 5, 2009 Hello, can some help me a bit please? I am trying to check two variables for the presence of a valu and do something different depending on the result. Currently I have: $var = xxx $var2 = yyy if(empty($var)) { if(empty($var2)) { echo ''; } } else { echo 'something else'; } It works under these conditions: $var is not empty, $var and $var2 both empty. It does not work when $var is empty but $var2 has value. Can someone assist me please? Thanks, Joe Quote Link to comment https://forums.phpfreaks.com/topic/148022-ifelse-help-brand-new-to-php/ Share on other sites More sharing options...
samshel Posted March 5, 2009 Share Posted March 5, 2009 <?php $var = "xxx"; $var2 = "yyy"; if(empty($var)) { if(empty($var2)) { echo 'Both 1 and 2 are Empty !!'; } else { echo '1 is Empty !!'; } } else { if(empty($var2)) { echo '2 is Empty !!'; } else { echo 'Both 1 and 2 are not Empty !!'; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/148022-ifelse-help-brand-new-to-php/#findComment-776935 Share on other sites More sharing options...
dt192 Posted March 5, 2009 Share Posted March 5, 2009 what are you actually cheking for do you need to test for all 4 combiations? Quote Link to comment https://forums.phpfreaks.com/topic/148022-ifelse-help-brand-new-to-php/#findComment-776938 Share on other sites More sharing options...
mathisjr Posted March 5, 2009 Author Share Posted March 5, 2009 what are you actually cheking for do you need to test for all 4 combiations? I am building at table of recipe instructions (Recipes for tying fishing flies). A user can upload up to 20 steps, each step can have a picture and a description or just one or the other. $var & $var2 represent theses two items. As I build the table for viewing, each echo statement will format the table row differently 1. Both entered, 2. only picture, 3. only the description, 4. neither available so nothing is echoed. Quote Link to comment https://forums.phpfreaks.com/topic/148022-ifelse-help-brand-new-to-php/#findComment-776976 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.