How can empty array fields be removed from an array in PHP?

When working with arrays in PHP, it is common to encounter empty array fields that need to be removed. This can be achieved by using the array_filter() function, which filters elements of an array using a callback function. The callback function can be used to remove empty values from the array.

// Example array with empty fields
$array = [1, 2, '', 4, null, 6];

// Remove empty fields from the array
$array = array_filter($array, function($value) {
    return $value !== '' && $value !== null;
});

print_r($array);