使用Get Parameters在PHP中创建链接

Imb*_*bue 1 php

我是php的新手,但我正在开发一个简单的网页.

此页面可以使用不同的参数进行配置.所以,它可以被称为:

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

现在我的问题是,生成到当前页面的链接但是有一个参数改变的成语是什么?

例如,我想将foo更改为5,生成链接的最简单方法是:

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!

Anp*_*her 8

你正在寻找array_merge()

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