Is there any function available in PHP to check whether an array is empty or how can I do this without using loop?
For example: $b = array('key1' => '', 'key2' => '', 'key3' => '', 'key4' => '');
How can I check array $b contains empty values without using a loop?
Simple:
function allEmpty($array)
{
return empty(array_filter($array)); // (PHP < 5.3) or
$array = array_filter($array); return empty($array); // (PHP >= 5.3) or just
return array_filter($array) === array();
}
function someEmpty($array)
{
return ($array !== array_filter($array));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With