parse_url() to extract the query string from the URL
parse_str() to split the query string into an array
array_merge() to add a new array "b" => 5
http_build_query() to re-build a query string
The remaining parts from the first step (protocol, host, path...) to re-build the full URL or - if you have the HTTP
pecl extension - a http_build_url() with HTTP_URL_JOIN_QUERY will alleviate much of the work.