Quantcast
Channel: Remove empty array elements - Stack Overflow
Browsing all 28 articles
Browse latest View live

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 Article


Answer 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 Article


Answer 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 Article

Answer 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 Article

Answer 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 Article


Answer by Mark Baker for Remove empty array elements

foreach($linksArray as $key => $link) { if($link === '') { unset($linksArray[$key]); } } print_r($linksArray);

View Article

Remove 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 Article

Answer 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

Browsing all 28 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>