Here’s how you can remove empty or whitespace elements in your array, and also reindex the array at the same time. Use array_filter
to remove the unwanted elements, and array_values
to reindex the elements.
$arr = array_values( array_filter($arr, function($item) { return !empty(trim($item)); }) ); // remove empty or whitespace elements in array.
Quick and simple solution.
Be First to Comment