-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
  • 22,779
  • 66
  • 183
  • 324

2 Answers2

0

You have to make a hack, for example:

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

You can use is_null() too.

Dimitri
  • 922
  • 2
  • 13
  • 34
-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,948
  • 1
  • 11
  • 16