How can array_filter() be utilized to remove empty elements from an array in PHP?

When working with arrays in PHP, it is common to encounter empty elements that need to be removed. The array_filter() function can be used to easily filter out these empty elements from an array. By passing a callback function that checks if each element is empty, array_filter() will return a new array with only the non-empty elements.

// Sample array with empty elements
$array = array("apple", "", "banana", "", "cherry");

// Remove empty elements from the array
$array = array_filter($array, function($value) {
    return $value !== "";
});

// Output the filtered array
print_r($array);