Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/148022-ifelse-help-brand-new-to-php/
Share on other sites

<?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 !!';
}
  
}
?>

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.