empty()

Yes, a new ‘cool tool’ that I discovered! Since many php funcitons will return a variety of different types, and since php is a loose-type language, I have found myself using this function a LOT.

So what does it do? Here is what php.net has to say about it:

Returns FALSE if var has a non-empty and non-zero value.
The following things are considered to be empty:
  • “” (an empty string)
  • 0 (0 as an integer)
  • 0.0 (0 as a float)
  • “0” (0 as a string)
  • NULL
  • FALSE
  • array() (an empty array)
  • var $var; (a variable declared, but without a value in a class)

So basically anything that would be considered a ‘false’ or a “no” is simply returned as a false. This makes my if() statements so much more shorter and readable.