PHP - Are empty arrays considered as null

6.8k Views Asked by At

The following code gives TRUE,FALSE,FALSE,FALSE, I dont understand the TRUE response on empty arrays. Someone has an explanation?

$results=array();
// Case 1 : Empty array
$myArray=array();
array_push($results, ($myArray==null));
array_push($results, ($myArray===null));
// Case 2 : Non Empty array
$myArray=array(1);
array_push($results,($myArray==null));
array_push($results,($myArray===null));
//
foreach ($results as $result) {
    if ($result) echo("TRUE,"); else echo ("FALSE,");
}
1

There are 1 best solutions below

0
On

Response here : PHP treats NULL, false, 0, and the empty string as equal, see stackoverflow here php is null or empty?

... and empty arrays

Need to be very careful so