If I have the url mysite.com/test.php?id=1. The id is set when the page loads and can be anything. There could also be others in there such as ?id=1&sort=new. Is there a way just to add another to the end without finding out what the others are first then building a new url? thanks.
If I have the url mysite.com/test.php?id=1 . The id is set when the page
Share
As an alternative to Kolink’s answer, I think I would utilize
http_build_query(). This way, if there is nothing in the query string, you don’t get an extra&. Although, it won’t really make a difference at all. Kolink’s answer is perfectly fine. I’m posting this mainly to introduce you tohttp_build_query(), as you will likely need it later:Basically, we use
http_build_query()to take everything in$_GET, and merge it with an array of any other parameters we want. In this example, I just create an array on the fly, using your example parameter. In practice, you’ll likely have an array like this somewhere already.