Piranha;10878205 wrote:From the manual
In other words, it will be regarded as empty with other values than an empty string, making those two ways totally different.
That would be correct if using the "===" operator, but the "==" does the same loose-typing conversion of 0/empty/false values.
<pre><?php
$testData = array(0, "0", "", false, null, 'only "true" value');
for($ix = 0; $ix < count($testData); $ix++)
{
echo "\nTest $ix\n";
var_dump($testData[$ix]);
echo "empty(): ";
$result = empty($testData[$ix]);
var_dump($result);
echo "== : ";
$result = ($testData[$ix] == '');
var_dump($result);
echo "=== : ";
$result = ($testData[$ix] === '');
var_dump($result);
}
?></pre>
Results:
Test 0
int(0)
empty(): bool(true)
== : bool(true)
=== : bool(false)
Test 1
string(1) "0"
empty(): bool(true)
== : bool(false)
=== : bool(false)
Test 2
string(0) ""
empty(): bool(true)
== : bool(true)
=== : bool(true)
Test 3
bool(false)
empty(): bool(true)
== : bool(true)
=== : bool(false)
Test 4
NULL
empty(): bool(true)
== : bool(true)
=== : bool(false)
Test 5
string(17) "only "true" value"
empty(): bool(false)
== : bool(false)
=== : bool(false)