0

How can i check if all has values do something if one is missing echo something with else. I try with isset but same, i miss something i think.

$da1="da1";
$ba2="";
$za3="za3";

if (!empty($da1)||!empty($ba2)||!empty($za3)) {
    echo $da1.$ba2.$za3;
}else{
    echo "one is missing";
}

My output is this :

da1za3
2
  • !empty($da1) is true, no other checks are done. you need to rethink your logic Commented Aug 20, 2017 at 8:05
  • You should be careful when using empty() and make sure that you know what it actually evaluates as empty. php.net/manual/en/function.empty.php Commented Aug 20, 2017 at 8:10

2 Answers 2

5

USE && instead ||

if (!empty($da1)  && !empty($ba2)  && !empty($za3)) {
    echo $da1.$ba2.$za3;
}else{
    echo "one is mising";
}
Sign up to request clarification or add additional context in comments.

9 Comments

isset only checks variable is set or not, it will not check its value (weather empty or not). Thanks
so what does exactly || ?
@AdrianKlark Thank you, some answers are stupid here they don't read the question. wont go down well, people are trying to help you. also || means or but hey we are all stupid!! If you took the time to read the manual you would know.
|| checks weather one of condition is true, then it returns true. In your case, $da1 is not empty, so it will not throwing error.
@DhruvilPatel isset() does check if it is null as well.
|
2

you can check with isset function

if(isset($da1,$da2,$da3))
    echo 'all ok';

1 Comment

Looks good, didn't know comma existed for this function

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.