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.
Call function like this
$result = remove_empty($array);
print_r($result);
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
Reviewed by JS Pixels
on
April 28, 2011
Rating:
No comments: