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\
You can simply walk the query params, if empty array, use "[]" instead, like this:
function walkCriteria(&$criteria) {
array_walk($criteria, function (&$val) {
if ($val === []) {
$val = "[]";
} else if (is_array($val)) {
walkCriteria($val);
}
});
}
Don't use array_walk_recursive. Because it will walk into the empty array and do nothing.