I have the array $var, and I\'d like to return FALSE if one or more element in the array are empty (I mean, the string are \"\").
I think that array_filter()
Or explicitly, as suggested by @Ancide:
$var = array("lorem", "ipsum", "dolor");
$emptyVar = array("lorem", "", "dolor");
function has_empty($array) {
foreach ($array as $value) {
if ($value == "")
return true;
}
return false;
}
echo '$var has ' . (has_empty($var) ? 'empty values' : 'no empty values');
echo '
';
echo '$emptyVar has ' . (has_empty($emptyVar) ? 'empty values' : 'no empty values');
EDIT:
I wasn't sure at first if array_search()
stops at first occurrence. After verifying PHP's source it seems that array_search()
approach should be faster (and shorter). Thus @Wh1T3h4Ck5's version would be preferable, I suppose.