开发者

Create link in PHP with Get Parameters

开发者 https://www.devze.com 2023-01-09 07:19 出处:网络
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

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.


array_merge() is what you're looking for

<a href="http://www.example.com/index.php?<?php echo http_build_query(array_merge($_GET, array('foo' => 5)), '', '&amp;');?>">link text</a>
0

精彩评论

暂无评论...
验证码 换一张
取 消