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 Altaf Hussain on 3:15 PM Rating: 5

No comments:

Altaf Web. Powered by Blogger.