Example cases:Need to add x=1, y=2 and querystring variables to the following URLs:http://www.foo.com/blah/blah?test=1&abc=2http://www.foo.com/blah//-- usageget_link(array('x' => 1, 'y' => 2, 'z' => 'string'));function get_link( $my_params ){       $param_querystring = ;    $http_host = $_SERVER['HTTP_HOST'];    //-- get the part of the url before the querystring, if applicable    $url = explode( '?', $_SERVER['REQUEST_URI'] );    $request_uri = $url[0];    $querystring = $url[1];    foreach ( $my_params as $param_key => $param_value )    {        $param_querystring .= $param_key . '=' . $param_value;    }    if ( empty( $querystring ) )    {        //-- generates foo.com/blah?x=1&y=2&z=string if no        //-- querystring was present        $link = $request_uri . '?' . $param_querystring;    }    else    {        //-- generates foo.com/blah?a=1&b=2&x=1&y=2&z=string if a=1&b=2         //-- querystring was already present.        $link = $request_uri . $querystring . '&' . $param_querystring;    }    return $link;}
Add a set of querystring params to a URL
php;url