我有一个名为$new_get的关联数组,它来自$_get的原始数组。不同的是,我修改了一些键和值,之后需要回显以创建新的URL。
我只是想把这个$new_get转换回它的原始形式,比如:
?something=this&page=2
我的$new_get看起来像:
$new_get = array (
'something' => 'this',
'page' => '2'
);
只需执行以下操作:
$query = "?" .http_build_query($new_get);
如果您的$new_get是以与$_get相同的方式构建的。
以下是我自己的一个功能,可以在实际的基础上创建一个新的URL查询:
// the array_of_queries_to_change will be numbered, the values in it will replace the old values of the link. example : 'array_of_queries_to_change[0] = "?page=4";'.
// the returned value is a completed query, with the "?", then the query. It includes the current page's one and the new ones added/changed.
function ChangeQuery($array_of_queries_to_change)
{
$array_of_queries_to_change_count = count($array_of_queries_to_change); // count how much db we have in total. count the inactives too.
$new_get = $_GET;
$i0 = 0;
// echo "///" .($get_print = print_r($_GET, true)) ."///<br />";
// echo "///" .($get_print = print_r($new_get, true)) ."///<br />";
while ($i0 < $array_of_queries_to_change_count)
{
$array_of_keys_of_array_of_queries_to_change = array_keys($array_of_queries_to_change);
$new_get[$array_of_keys_of_array_of_queries_to_change[$i0]] = $array_of_queries_to_change[$array_of_keys_of_array_of_queries_to_change[$i0]];
$i0++;
}
$query = "?" .http_build_query($new_get);
return $query;
}
/*// example of use :
$array_of_queries_to_change = array (
'page' => '2',
'a key' => 'a value'
);
$new_query = ChangeQuery($array_of_queries_to_change);
echo $new_query;
*/