Hello I know all about http://www.php.net/manual/en/function.http-build-query.php to do this however I have a little problem.
It \"handly\" turns boolean values into
I don't know of anything offhand. What I'd recommend is first iterating through the array and covert booleans to strings, then call http_build_query
E.g.
foreach($options_array as $key=>$value) :
if(is_bool($value) ){
$options_array[$key] = ($value) ? 'true' : 'false';
}
endforeach;
$options_string=http_build_query($options_array);
Try passing http_build_query true and false as strings instead of booleans. You may get different results.
If you just need to convert your true
/false
to "true"
/"false"
:
function aw_tostring (&$value,&$key) {
if ($value === true) {
$value = 'true';
}
else if ($value === false) {
$value = 'false';
}
}
array_walk($http_query,'aw_tostring');
// ... follow with your http_build_query() call
have a look at my wheel:
function buildSoQuery(array $array) {
$parts = array();
foreach ($array as $key => $value) {
$parts[] = urlencode($key).'='.(is_bool($value)?($value?'true':'false'):urlencode($value));
}
return implode('&', $parts);
}
Loop through each variable of the query string ($qs) and if bool true or false, then change value to string.
foreach($qs as $key=>$q) {
if($q === true) $qs[$key] = 'true';
elseif($q === false) $qs[$key] = 'false';
}
Then you can use the http_build_query()