$_GETの元の配列に由来する$new_getという連想配列があります。違いは、新しいURLを作成するためにエコーする必要があるキーと値の一部を変更したことです。
この$new_getを次のような元の形式に戻したいだけです。
?something=this&page=2
私の$new_getは次のようになります:
$new_get = array (
'something' => 'this',
'page' => '2'
);
$_GETの元の配列に由来する$new_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クエリに基づいて新しい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;
*/