I am trying to add params to a url but "&" is appearing twice.
it shows: "/getAllBrands?&key1=2&key2=1&limit=1"
I want it to be like this: "/getAllBrands?key1=2&limit=1"
url = sprintf("/%s?", $apiMethod);
$pos = strpos($url, "?");
foreach ($params[0] as $key => $value) {
if ($pos) {
$url .= "&";
}
$url .= sprintf('%s=%s', $key, urlencode($value));
}
Would appreciate if someone could help, thank you.
http_build_queryand save yourself with that hibbyjibby string manipulation