Parfum Shop's Blog

You come when you need, away when you get

Array remove empty entries PHP

By • Mar 18th, 2010 • Category: Web Programming

Bellow PHP code for remove an empty value of array:

function array_remove_empty($arr){
$narr = array();
while(list($key, $val) = each($arr)){
if (is_array($val)){
$val = array_remove_empty($val);
// does the result array contain anything?
if (count($val)!=0){
// yes :-)
$narr[$key] = $val;
}
}
else {
if (trim($val) != ""){
$narr[$key] = $val;
}
}
}
unset($arr);
return $narr;
}

is
Email this author | All posts by

One Response »

  1. makasih scriptnya, saya sedang membutuhkan fungsi remove an empty value.

Leave a Reply