-4

I need to check if an age is empty so I do:

empty($age);

But when the age is 0, it still thinks it is empty.

How can I check if the age is empty but allow a 0 to validate as not empty?

panthro
  • 21,049
  • 61
  • 166
  • 295

2 Answers2

0

You have to make a hack, for example:

if($age != "" && $age == false){
 // Age = 0
}

You can use is_null() too.

Dimitri
  • 912
  • 2
  • 13
  • 33
-1

Why do not you define it all your own

function myempty($x)
{
  if(empty($x) || $x=0)
  retutn true;
  else
  return false;
}
Rohit Kumar
  • 1,899
  • 1
  • 9
  • 16