我有一个名为 $new_get 的关联数组,它来自 $_GET 的原始数组。不同之处在于我修改了一些需要回显的键和值以创建新的 URL。
我只是想将此 $new_get 转换回它的原始形式,例如:
?something=this&page=2
我的 $new_get 看起来像:
$new_get = array (
'something' => 'this',
'page' => '2'
);
我有一个名为 $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;
*/