Skip to main content
Inspiring
November 2, 2006
Question

PHP Difference between empty and = ""

  • November 2, 2006
  • 11 replies
  • 507 views
Is there any major difference between empty and = ""? Perfomance, instances
where one is better over the other?

--

TIA,

Jon Parkhurst
PriivaWeb
http://priiva.net.


This topic has been closed for replies.

11 replies

Inspiring
November 2, 2006
crash wrote:
> Is there any major difference between empty and = ""?

The empty() function checks whether a variable is empty, as defined here:

http://www.php.net/manual/en/function.empty.php

= "" sets a variable to an empty string.

Do you mean the difference between using empty() and == ""?

If so, there is a major difference.

$variable = 0;

if (empty($variable)) // true
if ($variable == "") // false

--
David Powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/