Stack Exchange
PHP Validation check if even one value is empty in array
I would like to check validation if even one of the given array is String(0) or empty, it returns error
// OK Case
Array
(
    [1] => 1
    [2] => 
    [3] => 1
)

If even one is not empty it should return true.
Error case will be the following cases:
// Error Case
Array
(
    [1] => ''
    [2] => ''
    [3] => ''
)

or
// Error Case
Array
(
    [1] => 
    [2] => 
    [3] => 
)

My current code is below, but it is showing error if the last value is empty, even though there is a value at other indexes:
foreach ($array as $key => $value) {
    $value = trim($value);
    if (empty($value))
       //error
    else
       //ok
}


Where's your code?

If count(array_filter($arr)) != count($arr) then the array contains a 0, '', or null value.

foreach ($array as $key => $value) {
    $value = trim($value);
    if (empty($value))
        echo "$key empty <br/>";
    else
        echo "$key not empty <br/>";
}


Instead of looping, you should simply check the original count and filtered count: 
Filtered count basically gives you count of non-empty values: count(array_filter($arr))
And this will give you original count: count($arr)
Just compare above two and that will give your validation check.
