How do I check if array value is empty?

An other solution:

$array = array('one', 'two', '');

if(count(array_filter($array)) == count($array)) {
    echo 'OK';
} else {
    echo 'ERROR';
}

http://codepad.org/zF9KkqKl


It works as expected, third one is empty

http://codepad.org/yBIVBHj0

Maybe try to trim its value, just in case that third value would be just a space.

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

You can check for an empty array by using the following:

if ( !empty(array_filter($array))) {
    echo 'OK';
} else {
    echo 'EMPTY ARRAY';
}

Tags:

Php