Remove empty array values

Views: 8 Last modified: September 17th, 2011 Comments: 0

This snippet will remove all the empty values from an array and returns the cleared array. If the input is not an array, it will return false

Example of use:

print_r(clear_empty_values($array));
function clear_empty_values($arr)
{
	if (!is_array($arr)) return false;
	$new = array();
	while(list($k, $v) = each($arr))
	{
		$v = trim($v);
		if ($v != '' || !empty($v)) $new[$k] = $v;
	}

	return $new;
}
VN:F [1.9.13_1145]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.13_1145]
Rating: 0 (from 0 votes)

    Mail this!

    To: From:Sum {3+6} =  
    Anything to add ?

        You must be logged in to post a comment.