PHP has built in function http_build_query that can be used to prepare a query string from an array.
Instead of explicitly appending elements to string, this function comes handy, which takes cares of generating URL-encoded query string either from an associative or indexed array.