I ran into a problem today where I was passing a key with the value set to an empty array to http_build_query()
. E.g.:
$args = array(\"foo\", \"bar\
Building on @anyx solution: If you want to preserve the original array and also handle NULL values, you can use this version:
function empty2blank(array $arr) {
array_walk($arr, function(&$val, $key) {
if (empty($val)) {
$val = is_array($val) ? '[]' : '';
} elseif (is_array($val)) {
$val = empty2blank($val);
}
});
return $arr;
}