Answer by matija kancijan for Remove empty array elements
$myarray = array_filter($myarray, 'strlen'); //removes null values but leaves "0" $myarray = array_filter($myarray); //removes all null values
View ArticleAnswer by marcovtwout for Remove empty array elements
Another one liner to remove empty ("" empty string) elements from your array. $array = array_filter($array, function($a) {return $a !== "";}); Note: This code deliberately keeps null, 0 and false...
View ArticleAnswer by Andrew Moore for Remove empty array elements
You can use array_filter to remove empty elements: $emptyRemoved = array_filter($linksArray); If you have (int) 0 in your array, you may use the following: $emptyRemoved = remove_empty($linksArray);...
View ArticleAnswer by tamasd for Remove empty array elements
$linksArray = array_filter($linksArray); "If no callback is supplied, all entries of input equal to FALSE will be removed." -- http://php.net/manual/en/function.array-filter.php
View ArticleAnswer by BoltClock for Remove empty array elements
As you're dealing with an array of strings, you can simply use array_filter(), which conveniently handles all this for you: print_r(array_filter($linksArray)); Keep in mind that if no callback is...
View ArticleAnswer by Mark Baker for Remove empty array elements
foreach($linksArray as $key => $link) { if($link === '') { unset($linksArray[$key]); } } print_r($linksArray);
View ArticleRemove empty array elements
Some elements in my array are empty strings based on what the user has submitted. I need to remove those elements. I have this: foreach($linksArray as $link) { if($link == '') { unset($link); } }...
View ArticleAnswer by Rain for Remove empty array elements
I think array_walk is much more suitable here$linksArray = array('name', '', ' 342', '0', 0.0, null, '', false); array_walk($linksArray, function(&$v, $k) use (&$linksArray){ $v = trim($v); if...
View Article