Cutting straight to the point, here’s a quick way with PHP for removing empty values from an array and shifting the indices appropriately. Nothing too fancy but I found it useful at work and figure that I might as well share the tip.
<?php $array = array('apples', 'oranges', '', 'bananas', null); $filteredarray = array_values( array_filter($array) ); print_r($filteredarray); ?>
The above will output:
Array (  => apples  => oranges  => bananas )