Skip to content

Instantly share code, notes, and snippets.

@michaeldyrynda
Created October 26, 2015 23:15
Show Gist options
  • Save michaeldyrynda/f8df4909a01e009624bc to your computer and use it in GitHub Desktop.
Save michaeldyrynda/f8df4909a01e009624bc to your computer and use it in GitHub Desktop.
Helper function to clean empty array values from a one-dimensional array input
<?php
/**
* Ensure that the input array has no empty-string values assigned.
*
* @param array $array
*
* @return array
*/
function array_clean(array $array)
{
// Trim the array input values
$array = array_map('trim', $array);
// Filter any empty-string values out
return array_filter($array, function ($item) {
return $item !== '';
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment