2
if($_POST['cropProfileData'] == undefined || $_POST['cropProfileData'] == null || $_POST['cropProfileData'] == 0) {
    echo "NO process profile photo....";
}else{
    echo "YES process profile photo....";
}

this works fine - it shows me if the array is empty.

The catch is I only need the 'echo "YES process profile photo...".

How can I get the NOT of the above IF statement? I've tried added '!' after the if - eg: if!( and I've tried added '!' after each of the 3 statements.

Is there a way to get the NOT of this statement - will save me a having to include the else which is pointless code.

thx

PS: the reason for this is to see if the array is empty.

5
  • 4
    You have posted PHP code, but tagged it with "jQuery". There is no PHP vlaue like undefined Well, it's monday… Commented May 6, 2013 at 8:00
  • Have you tried this - $_POST['cropProfileData'] != undefined || Commented May 6, 2013 at 8:00
  • yes I have... I'll update the question... thankyou n sorry Commented May 6, 2013 at 8:01
  • 1
    What is this undefined constant? Commented May 6, 2013 at 8:05
  • Undefined must have come from JavaScript Commented May 6, 2013 at 8:05

4 Answers 4

4

Just !empty( $_POST[ 'cropProfileData' ] ) will cover all those cases (although undefined is not used in PHP unless it's some constant).

if( !empty( $_POST[ 'cropProfileData' ] ) ) {
    echo "YES process profile photo....";
}
Sign up to request clarification or add additional context in comments.

1 Comment

This doesn't strictly check for a non-empty array.
2

Theory

The negative expression is simply this:

if (!($_POST['cropProfileData'] == undefined || $_POST['cropProfileData'] == null || $_POST['cropProfileData'] == 0)) {

According to De Morgan, the expression could also be written as:

if ($_POST['cropProfileData'] != undefined && $_POST['cropProfileData'] != null && $_POST['cropProfileData'] != 0) {

Practice

To test if something is undefined you should use isset(), for example:

$_POST['cropProfileData'] == undefined || $_POST['cropProfileData'] == null

Should be written as:

!isset($_POST['cropProfileData'])

To specifically test if an array is not empty:

isset($_POST['cropProfileData']) && is_array($_POST['cropProfileData']) && count($_POST['cropProfileData'])

Or, simpler:

if (!empty($_POST['cropProfileData']) && is_array($_POST['cropProfileData'])) {

Comments

1
<?php

/*
if($a == undefined || $b == null || $c == 0) {
    echo "NO process profile photo....";
}else{
    echo "YES process profile photo....";
}
*/


if($a != undefined && $b != null && $c != 0) {
    echo "NO process profile photo....";
}else{
    echo "YES process profile photo....";
}


?>

Comments

1

You just need to check that array is empty or not

like

if(!empty( $_POST[ 'cropProfileData' ] )){echo "YES process profile photo....";}

Comments

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.