Add variables to $_GET for url link

When working with links containing forms on the same page, you sometimes don’t want to lose the data. Especially if you switch languages after a search. You can easily build a query with old and new variables.

$variables = array_merge($_GET, array("a" => "value1", "b" => "value2"));
$queryString = http_build_query($variables);

//Result: ?old1=that&old2=this&a=value1&b=value2

Be the first to comment “Add variables to $_GET for url link”

This site uses Akismet to reduce spam. Learn how your comment data is processed.