Thursday, September 21, 2017

0.00 is not empty in empty() php

When we get value like '0.00' from database and we check if it is empty

 if(!empty(0.00)){
      return true;
}

this will return true because, it understand 0.00 is not a number it is a string.


according to php manual a variable is empty if meeting anyone of the following case:

If we want to make it / understand it as a empty then we need to use this
$amount = 0.00;

(float)$amount; 

Now this will return as 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)
  •  
  • Total Pageviews