Created
October 26, 2015 23:15
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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