1

I'm sending a parameter with post. This parameter holds a ZERO value.

When i'm trying to use the empty method it should return 1 if the parameter is not empty and 0 if the parameter is zero.

If i'm using this code:

var_dump(empty($_REQUEST['gender_preferences']) );

i'm getting the result: 1.

If i'm using this code:

var_dump(!empty($_REQUEST['gender_preferences']) );

i'm not getting the 0 value;

Why does this happen and how can i fix it?

1
  • 1) what is a ZERO value 2) "should return 1 if the parameter is not empty" - huh? doesn't that contradict its name LOL 3) it's unclear what you actually want to do. Commented Mar 5, 2014 at 9:41

2 Answers 2

5

The following things are considered to be empty:

""  /* (an empty string) */
0  /* (0 as an integer)*/
"0"  /* (0 as a string)*/
NULL
FALSE
array() /*  (an empty array)*/
var $var;  /* (a variable declared, but without a value in a class)*/

Try using isset instead

isset($_REQUEST['gender_preferences'])
Sign up to request clarification or add additional context in comments.

2 Comments

how can you suggest isset without knowing what he wants to do? that's quite irresponible.
Read the question clearly, he describes what he wants.
0

empty function Determine whether a variable is empty or not and your requested variable contains value i.e zero 0.

to check variable contains zero

if($_REQUEST['gender_preferences']){
  //value is not zero
}else{
  //value is zero
}

1 Comment

just.... don't. check the last column: us3.php.net/manual/en/types.comparisons.php

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.