Remove empty elements from php array

Want to get rid of empty elements from an array. Use this function. Just pass the array to the function. It will return resultant array without empty elements.

  function remove_empty($array) {
    foreach($array as $key => $value){
      if(trim($value) == ''){
         unset($array[$key]);
      }
    }
  return $array;
  }


Call function like this

$result = remove_empty($array);
print_r($result);
Remove empty elements from php array Remove empty elements from php array Reviewed by JS Pixels on April 28, 2011 Rating: 5

No comments:

Altaf Web. Powered by Blogger.