I have the following code
<?php
$error = array();
$error['something'] = false;
$error['somethingelse'] = false;
if (!empty($error))
{
echo 'Error';
}
else
{
echo 'No errors';
}
?>
However, empty($error) still returns true, even though nothing is set.
What’s not right?
There are two elements in array and this definitely doesn’t mean that array is empty. As a quick workaround you can do following:
array_filter()function’s default behavior will remove all values from array which are equal tonull,0,''orfalse.Otherwise in your particular case
empty()construct will always returntrueif there is at least one element even with “empty” value.