Posted By


mattlowden on 09/25/10

Tagged


Statistics


Viewed 214 times
Favorited by 0 user(s)

array_remove_null


/ Published in: PHP
Save to your folder(s)

Remove null values from array with the option to maintain or discard keys.


Copy this code and paste it in your HTML
  1. function array_remove_null(&$array, $maintian_keys = true){
  2. $new_array = array();
  3. if(is_array($array)){
  4. foreach($array as $k=>$v){
  5. if($v&&$maintian_keys) $new_array[$k]=$v;
  6. elseif($v) $new_array[]=$v;
  7. }
  8. }
  9. $array = $new_array;
  10. return $array;
  11. }

URL: http://www.mattlowden.com/blog/2009/07/removing-null-values-in-a-php-array/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.