tags:

views:

24

answers:

1

I'm really new to php, but I'm working on a simple web page.

This page is quite configurable with different parameters. So, it may be called like:

www.example.com/index.php?test=1&foo=3&bar=4

Now my question is, what is the idiom for generating a link to the current page but with one parameter changed?

For example, I'd like to change foo to 5, what's the easiest way to generate a link like:

www.example.com/index.php?test=1&foo=5&bar=4

I can loop through and do it manually, but I figured there would be some common idiom for this.

Thanks a ton!

+5  A: 

array_merge() is what you're looking for

<a href="http://www.example.com/index.php?&lt;?php echo http_build_query(array_merge($_GET, array('foo' => 5)), '', '&amp;');?>">link text</a>
Anpher
Perfect, this is why I love Stack Overflow.
Imbue
+1 and [`http_build_query()`](http://uk2.php.net/manual/en/function.http-build-query.php) - thanks for reminding me about that one!
w3d